Front and rear side validation username Case (php, mysql combined)
html front end portion of the browser:
<html> <head> <meta charset='utf-8'/> <title>注册和登录</title> </head> <body> <form action="http://10.36.150.38/0722/08register.php" method="get"> <p> <label for="un">用户名:</label> <input type="text" name='username' id='un'> </p> <p> <label for="pd">密码:</label> <input type="text" name="password" id="pd"> </p> <p> <input type="submit" value="注册"> </p> </form> </body> </html>
php code portion
? < PHP header ( 'Content-of the type: text / HTML; charset = UTF-8' ); $ name = $ _REQUEST [ 'username']; // get the user name $ pw = $ _REQUEST [ 'password']; / / obtain the password // connect to the database: five parameters $ SQL = mysqli_connect ( 'localhost', 'root', 'root', 'UserInfo', '3306' );
// mysqli_connect ( 'HTTP address', database user name, database password, database name, port number); // echo $ name; // echo $ pw; IF ( mysqli_connect_error ()) { echo "database connection failed" ; return; } // echo "database connection success!"; // database query, the presence of the user $ the Result = mysqli_query ( $ SQL , "the SELECT name info from the WHERE name = ' $ name ' ' ); // number of rows in the query results rows $ = mysqli_num_rows ( $ result ); IF ( $ rows > 0 ) { // database query to the result, the same name echo "user name already exists, click Retry <a href = 'http: // localhost / 0722 / form .html '> retry </a> " ; } the else { $ BOOL = the mysqli_query ( $ SQL, "INSERT INTO info (name, password) VALUES ( ' $ name ', ' $ pw ')" ); IF ( $ BOOL ) { echo "Congratulations on your successful registration, after three seconds to jump to the login page!" ; } } ?>