PHP background database and foreground request combined

Source: Internet
Author: User

  $_getGet the parameter value in a GET request$username=$_get["UserName"];$password=$_get["Password"];Echo("Username:".$username."Password:".$password) *///POST request, open Web page no value//Gets the value of the two variables in the body body,/*$username=$_post["username"];$password=$_post["Password"];if($username=="Houzhichao"&&$password==12345) {$dic= Array ("Code"= $,"Message"="Login Successful");Echo(Json_encode ($dic)); }Else{$dic= Array ("Code"=404,"Message"="Login Failed");Echo(Json_encode ($dic)); }*///register with the database to use, the foreground write something, write to the server database//1. Gets the value of the parameter in the user get body$username=$_get[Username];$password=$_get[password];//2. Using the database//(1) Connection Database mysql_connect//parameters1: Service//Parameters2: User name of login database, we select root user//parameter3: Password, when empty, can save//* * has a return value BOOL$islink= Mysql_connect ("127.0.0.1","Root","");if($islink) {Echo("Database connection succeeded
"); // (2) Select Database mysql_select_db mysql_select_db ("DataBase"); // (3Query the user table in the database, there is no current user name; return value (instruction set or BOOL) mysql_query//Results is an array (all records), querying all the contents$results= mysql_query ("Select username from users"); while($row= Mysql_fetch_array ($results) {//Determine if the user name in the row record is the same as the currently registered user nameif($row["username"] ==$username) {Echo("Registration failed, user name already exists
");return; }}//can register the operation//the equivalent of inserting data into a table of users$result= mysql_query ("INSERT into users (Username,password) VALUES ('$username', '$password')");if($result) {Echo("Registration Successful
"); }Else{Echo("Registration failed
"); }}Else{Echo("link Failed");}? >

'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
  • '). Text (i)); }; $numbering. FadeIn (1700); }); });

    The above introduces the PHP background database and the foreground request to combine, including the aspect of the content, I hope that the PHP tutorial interested in a friend helpful.

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