Passing parameter instance code between PHP pages _ PHP Tutorial

Source: Internet
Author: User
Pass the parameter instance code between PHP pages. 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. The first step is to show you 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" ";While ($ row = mysql_fetch_object ($ rs) echo" ";Echo"
Department Name
$ Row-> depart $ Row-> ename
";

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.

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.