Four, send data to the server Now we don't have much difficulty reading data from the database. But how do you send data to the database in turn? In fact, this is not a problem with PHP. First, we create a Web page with a simple table.
|
$#@60;html$#@62;
$#@60;body$#@62;
$#@60;form method= "POST" action= "$#@60;? PHP echo $PATH _info?$#@62; " $#@62;
Name: $#@60;input type= "Text" name= "one" $#@62;$#@60;br$#@62;
Surname: $#@60;input type= "Text" Name= "last" $#@62;$#@60;br$#@62;
Address: $#@60;input type= "Text" name= "addresses" $#@62;$#@60;BR$#@62;
Position: $#@60;input type= "Text" name= "position" $#@62;$#@60;br$#@62;
$#@60;input type= "Submit" name= "submit" value= "input information" $#@62;
$#@60;/form$#@62;
$#@60;/body$#@62;
$#@60;/html$#@62; |
Also pay attention to the use of $path_info. As I mentioned in the first lesson, you can use PHP anywhere in the HTML code. You will also notice that each element in the table corresponds to a field in the database. This correspondence is not necessary, it is only a little more intuitive to make it easier for you to understand the code later. Also note that I added the name attribute to the Submit button. So I can test the existence of $submit variables in the program. Then, when the page is called again, I know whether the page has been filled in with the form when it is called. I should point out that you do not have to write the contents of the above page into a PHP program, and then come back and call the program itself. You can put the page that shows the table and the process of processing the table separately on two pages, three pages or even more pages, whichever you want. Putting it in a file can only make the content more compact. Well, now we're going to add some code to check what the user has entered into the table. I'll show all the query parameter variables with $http_post_vars, just to show that PHP does pass all variables to the program. This method is a very useful debugging tool. If you want to see all the variables, you can use $globals.
|
$#@60;html$#@62; $#@60;body$#@62; $#@60;? PHP if ($submit) { //Process table input while ($name, $value) = each ($HTTP _post_vars)) { echo "$name = $value $#@60;br$#@62;\n"; } } else{ //Show Table $#@62; $#@60;form method= "POST" action= "$#@60;? PHP echo $PATH _info?$#@62; " $#@62; Name: $#@60;input type= "Text" name= "one" $#@62;$#@60;br$#@62; Surname: $#@60;input type= "Text" Name= "last" $#@62;$#@60;br$#@62; Address: $#@60;input type= "Text" name= "addresses" $#@62;$#@60;BR$#@62; Position: $#@60;input type= "Text" name= "position" $#@62;$#@60;br$#@62; $#@60;input type= "Submit" name= "submit" value= "input info" $#@62; $#@60;/form$#@62; $#@60;? PHP }//End If,if ? $#@62; $#@60;/body$#@62; $#@60;/html$#@62; |
|