/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function register( $user, $pass, $pass2 ) { { //Escape is a function with mysql_real_escape_string() and more $user = escape( $user ); $pass = escape( $pass ); $pass2 = escape( $pass2 ); { $error = "Username missing!"; } { $error = "Password missing!"; } { $error = "Please repeat your password!"; } else if ( $pass != $pass2 ) { $error = "Your passwords do not match!"; } { $error = "Username is to long, 25 characters max!"; } { $error = "Password is to long, 25 characters max!"; } { $error = "Password is to short, 5 characters min!"; } //I use trim to check if a user has a username with only whitespace, not using regex since having a whitespace in the username should be ok { $error = "Usernames only containing white-spaces is not allowed!"; } else { $fetch = mysql_query( "SELECT `user` FROM `user` WHERE `user` = '".$user."'" ) or die ( mysql_error() ); { $error = "That username is already taken!"; } else { mysql_query( "INSERT INTO `user` ( `user`, `pass` ) VALUES ( '".$user."', '".$pass."' )" ) or die ( mysql_error() ); } } } }