When you enter the data and press the Submit button, the form will send the data to the SUBMITFORM.PHP3. This PHP script is then processed to receive the data, the following is the SUBMITFORM.PHP3 code:
The "username" and "password" in the third line of the code represent the account and password you logged into the MySQL database. The "dbname" in line fifth indicates the name of the MySQL database. The "tablename" in line 13th is the name of a data table in the database.
When you press submit, you can see that the name you entered is displayed on a new page. Take a look at the URL bar of the browser and it should be something like this:
.../submitform.php3?first_name=fred&last_name=flintstone
Because we use the form get method, the data is routed to submitform.php3 through the URL. Obviously, the Get method is limited, and when there is a lot of content to be passed, you can't use GET, only the POST method. But no matter what the method, when the data transfer is complete, PHP automatically creates a variable that is the same as their name (the form's Name property) for each field in the form.
PHP variables have all started with a dollar sign, so that in the process of SUBMITFORM.PHP3 script processing, there will be $first _name and $last _name These two variables, the contents of the variable is what you entered.
Let's check to see if the name you typed is actually entered into the database. To start MySQL, at the mysql> prompt, enter:
Mysql> SELECT * FROM TableName;
You should be able to get a table with the content that you just typed:
------------ ------------
| first_name | last_name |
------------ ------------
| Willow | such as wind
------------ ------------
1 rows in Set (0.00 sec)
Let's analyze how SUBMITFORM.PHP3 works:
The first two lines of the script are:
mysql_connect (localhost, username, password);
mysql_select_db (dbname);
These two function calls are used to open the MySQL database, the meaning of the specific parameters has just been said.
The following line executes an SQL statement:
mysql_query ("INSERT INTO tablename (first_name, last_name)
VALUES ('$first_name', '$last_name')
");