Example Introduction
1. Query employee information, you can query employee basic information by entering employee number;
2. New employee information, including employee name, employee number, gender, employee position;
Realize:
1. Pure HTML page, used to implement employee query and new page;
2.php page to implement a background interface for querying employees and creating new employees
Introduction to PHP
PHP is a server-side scripting language for creating dynamic interactive sites
PHP can generate dynamic page content
PHP can create, open, read, write, delete, and close files on the server
PHP can receive form data
PHP can send and retrieve cookies
PHP can add, delete, and modify data in a database
PHP can restrict access to certain pages in the site
PHP section:
1<?PHP2 //Set page content is HTML encoded format is Utf-83 Header("Content-type:text/plain;charset=utf-8"); 4 //header ("Content-type:application/json;charset=utf-8");5 //header ("Content-type:text/xml;charset=utf-8");6 //header ("Content-type:text/html;charset=utf-8");7 //header ("Content-type:application/javascript;charset=utf-8");8 9 //Define a multidimensional array that contains information about employees, each employee information is an arrayTen $staff=Array One ( A Array("Name" = "Hong Qi", "Number" and "101", "sex" = "male", "job" and "General manager"), - Array("Name" = "Guo Jing", "number" = "102", "sex" = "male", "job" and "Development Engineer"), - Array("Name" = "Huang Rong", "number" = "103", "sex" = "female", "job" and "Product manager") the ); - - //determine if a GET request is being searched, and if it is a POST request, create a new - //$_server is a hyper-global variable that is available in all scopes of a script without using the Global keyword + //$_server["Request_method"] returns the request method used by the access page - if($_server["request_method"] = = "GET") { + search (); A}ElseIf($_server["request_method"] = = "POST"){ at Create (); - } - - //Search employees by employee number - functionsearch () { - //Check if there is an employee number parameter in //isset The detection variable is set; empty determines whether the value is null - //Hyper Global variables $_get and $_post for collecting form data to if(!isset($_get["Number"]) ||Empty($_get["Number"])) { + Echo"Parameter Error"; - return; the } * //variables declared outside the function have Global scope and can only be accessed outside of the function. $ //global keyword for accessing global variables within a functionPanax Notoginseng Global $staff; - //Get number parameter the $number=$_get["Number"]; + $result= "No employees found." "; A the //traverse the $staff multidimensional array to find out if an employee with a key value of number exists, and if so, modify the return result + foreach($staff as $value) { - if($value["number"] = =$number) { $ $result= "Find Employee: Employee Number:".$value["Number"]. ", Employee Name:".$value["Name"]. $", Employee Gender:".$value["Sex"]. ", Employee Position:".$value["Job"]; - Break; - } the } - Echo $result;Wuyi } the - //Create an employee Wu functionCreate () { - //Determine if the information is fully filled About if(!isset($_post["Name"]) ||Empty($_post["Name"]) $|| !isset($_post["Number"]) ||Empty($_post["Number"]) -|| !isset($_post["Sex"]) ||Empty($_post["Sex"]) -|| !isset($_post["Job"]) ||Empty($_post["Job"])) { - Echo"Incorrect parameter, incomplete filling of employee information"; A return; + } the //TODO: Get post form data and save to database - $ //Prompt Save successful the Echo"Employee:".$_post["Name"]. "Information saved successfully!" "; the}
Ajax Full-Touch (2)