Home  >  Article  >  Backend Development  >  Example code for passing parameters between PHP pages_PHP tutorial

Example code for passing parameters between PHP pages_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:51:29786browse


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



Depart Name:







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

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.

www.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...
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