Starting from today, we have entered the most basic but critical introduction stage of the php addition, deletion, and search functions in system production. First, we will introduce how to query data by passing values in a form.
Task target: Enter the department name in the form to query the personnel information of the corresponding department.
Create a search. php file first.
Step 1: insert a form that contains an input box and a submit button. The content of the search. php file is as follows:
The code is as follows:
Search
In this way, we get a data submission page, which means that when we click the Search button, the system passes the data entered in the input box named depart to the search_result.php file through the Post method.
Step 2: Since we have already transferred the value, we need to create another page file to receive the value. Because it has already been specified to be transferred to search_result.php, we will create a file named search_result.php.
In this file, first connect to the database and select the data source:
The code is as follows:
$ Link = mysql_connect ("localhost", "root", "previous administrator password ");
If (! $ Link) echo "no connection successful! ";
Else echo "connection successful! ";
Mysql_select_db ("infosystem", $ link );
?>
Then, the system receives the parameters from the search. php file and generates the SQL query statement:
The code is as follows:
$ Depart = $ _ POST ["depart"];
$ Q = "SELECT * FROM info where depart = '$ depart '";
?>
Finally, execute the SQL statement and display the data:
The code is as follows:
Mysql_query ("set names GB2312 ");
$ Rs = mysql_query ($ q, $ link );
Echo"
";Echo"
| Department |
Name |
";While ($ row = mysql_fetch_object ($ rs) echo"
| $ Row-> depart |
$ Row-> ename |
";Echo"
";
Mysql_close ($ link );
?>
After querying, do you get the data you need? Of course, this is just the most basic example. in the next few topics, I will continue to explain how to query the data.