Php code example for user registration
| This article describes how to check and store user registration information in php. For more information, see.
The code is as follows:
Query ('set names gb2312 '); if (empty ($ conn) {die ("database connection failed");} $ UserName = $ _ POST ['username']; $ pwd =$ _ POST ['password']; $ email =$ _ POST ['email ']; $ sex =$ _ POST ['sex']; $ time = time (); $ code = strtolower ($ _ POST ["code"]); $ str = "select * from users where username = '". $ username. "'"; $ result1 = $ conn-> query ($ str); $ row = $ result1-> fetch_row (); if ($ row) {$ temp = "already registered this name. please select another name! "; Echo $ temp; echo" back ";} else {if ($ _ SESSION ['sname'] = $ code) {echo $ temp =" authentication code successful "; $ SQL = "INSERT INTO users VALUES ('$ username',' $ password', '$ email', '$ sex',' $ time ')"; $ result = $ conn-> query ($ SQL); if ($ result = true) {$ _ SESSION ['mail'] = "registration successful, please log in "; echo "";} else {echo "registration failed ". mysql_error () ;}} else {echo "incorrect verification code" ;}}?>
The above code receives parameters from the registration page, including the user name, password, email address, gender, and verification code. Then, check whether the registration has been completed. otherwise, write the registration information to the database. Very simple, especially suitable for reference by new friends. |