Home >Backend Development >PHP Tutorial >put your head on my shoulder Example code for passing parameters between PHP pages

put your head on my shoulder Example code for passing parameters between PHP pages

WBOY
WBOYOriginal
2016-07-29 08:38:08997browse

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>

Depart Name:





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 "";
while($row = mysql_fetch_object($rs)) echo "";
echo "
Department
$row->depart $row->ename
";
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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn