First of all, I will introduce to you how to query data by passing values in the form.
Task goal: Enter the department name in the form and query the personnel information of the corresponding department.
First create the search.php file.
The first step is to insert a form, which contains an input box and a submit button. The content of the search.php file is as follows:
Copy the code The code is as follows:
Search< /h3>
In this way, we 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 part to the search_result.php file through the Post method.
The second step, since we have sent the value before, we need to create another page file to receive this value. Because it has been specified before that it is sent to search_result.php, then we will create a new file named search_result.php.
In this file, first connect to the database and select the data source:
Copy the code The code is as follows:
$link=mysql_connect("localhost","root","before Administrator password");
if(! $link) echo "No connection successful!";
else echo "Connection successful!";
mysql_select_db("infosystem", $link);
?>
Next , receive the parameters sent by the search.php file, and generate SQL query statements:
Copy the code The code is as follows:
$depart=$_POST["depart"];
$q = "SELECT * FROM info where depart='$depart'";
?>
Finally, execute the SQL statement and display the data:
Copy the code The code is as follows:
mysql_query ("SET NAMES GB2312");
$rs = mysql_query($q, $link);
echo "
";
echo "Department | |
";
while($row = mysql_fetch_object($rs)) echo "$row->depart | $row->ename |
";
echo "
";
mysql_close($link);
?>
Through query, are you getting what you need? Where is the data? Of course, this is just the most basic example. In the next few topics, I will continue to add explanations on the issue of querying data.
The above introduces the example code for passing parameters between put your head on my shoulder PHP pages, including the content of put your head on my shoulder. I hope it will be helpful to friends who are interested in PHP tutorials.