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
In this way, we get A data submission page means that when we click the Search button, the system will pass the data entered in the input box named depart 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","Previous administrator password");
if(! $link) echo "The connection was not successful! ";
else echo "Connection successful!";
mysql_select_db("infosystem", $link);
?>
Secondly, receive the search.php file sent Parameters, and generate SQL query statements:
Copy code The code is as follows:
$depart=$_POST["depart"];
$q = "SELECT * FROM info where depart='$depart'";
?>
Finally, execute SQL Statement and display data:
Copy code 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 td> | $row->ename |
";
echo "
";
mysql_close($link);
?>
Through the query, did you get the data you need? 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.
http://www.bkjia.com/PHPjc/319156.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319156.htmlTechArticleFirst 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. Step one...