The use of PHP to connect the MySQL database to achieve a simple user login registration and modify the Password API interface, the interface for the standard JSON output, local validation through. function is relatively simple, but also their own groping for a long time, a variety of Baidu to solve a variety of do not understand. The database has only the name, PSD, and Tel three fields, and the interface is designed for post submission. The code basically has the annotation to be better understood, the following enclose the code.
[PHP] View plain copy <?php $mysql _server_name= "localhost"; // Database server name $mysql _username= "root"; // connection database user name $mysql _password= "326699"; // Connection Database Password $mysql _ database= "Hello"; // database name // Connect to database $conn =mysql_connect ($mysql _server_name, $mysql _ username, $mysql _password); if (! $conn) { echo database connection failed. ".mysql_error; } mysql_select_db ($mysql _ database, $conn); //Get URL parameters $action = isset ($_post[' action ')] ? $_post[' action '] : '; $name = isset ($_post[' name ') ? $_post[' name '] : ' '; $psd = isset ($_post[' PSD ']) ? $_post[' psd '] '; if ($action = = ' Login ') { login ($name, $psd, true); } else if ($action = = ' register ') { register ($name, $psd); } else if ($ action== ' modifypsd ') { modifypsd ($name, $ PSD); } else if ($action = = ' ShowAll ') { showall (); } else { $result = array ("result" => "error_request"); $json = json_encode ($result); echo $json; } close_conn (); /* User Login */ function login ($name, $PSD