| Topic: PHP & MySQL PHP With Forms This page will provide an example login form for authenticating to mysql server. It also establishes a user session, and processes the results of the form. It connects to the database server after the form has been submitted and shows a list of available databases for review. The section about sessions explains how that part of the code works. The section called "MySQL Example" has the code that allows the user to select a table in the database and display the contents of the table. The listing of the "dblist.php" file is shown in that section which is numbered as item 14. Processing the Form Data Now lets create process.php to use the data from the HTML form we made:
You should now have some notion of how to use HTML to get input from a user. We will now investigate what you can do with PHP once you have that input. For this discussion we will focus on the built-in PHP functions isset() and empty(), and see how they can be used with conditionals. We will then use an interactive PHP application that can display its own code to clarify how all of these ideas work together.
<?php As you may be aware, if you leave out the method="post" part of the form, the URL with show the data. For example if your name is Bill Jones and you are 35 years old, our process.php page will display as The built-in PHP functions isset() and empty() are different, but the difference between them can be confusing.
To make the definitions of isset() and empty() more rigorous consider the following, which demonstrates the conditions under which they will return True or False, given the values of the variable $var. These examples are meant to demonstrate the truth values that the functions isset() and empty() would return. Not all of the following is valid PHP. The statement "f(x) == F" means the function f of argument x returns False and the statement "f(x) == T" means the function f of argument x returns True. The asterisk (*) is used to call attention to what changes are made, as the value of $var changes. $var; isset($var) == F * empty($var) == T $var = ""; isset($var) == T * empty($var) == T * $var = "x"; isset($var) == T empty($var) == F **
|
| Prev |