Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include('connect.php');
- function died($error)
- {
- echo "Error: <br /><br />";
- echo $error."<br /><br />";
- die();
- }
- //Variables
- $name = $_POST[name];
- $email = $_POST[email];
- $email_confirm = $_POST[email_confirm];
- $username = $_POST[username];
- $password = $_POST[password];
- $password_confirm = $_POST[password_confirm];
- //end of variables
- if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['email_confirm']) || !isset($_POST['username']) || !isset($_POST['password']) || !isset($_POST['password_confirm']))
- {
- died('It appears that you did not enter all the required information');
- }
- $error_message = "";
- $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$"; //Define witch characters are ok
- if(!eregi($email_exp,$email)) //Check for invalid characters in email
- {
- $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; //give error message is characters in email is invalid
- }
- $string_exp = "^[a-z .'-]+$"; //Definte what is ok to have in your name
- if(!eregi($string_exp,$name)) //check if the user has valid characters in his name
- {
- $error_message .= 'The Name you entered does not appear to be valid.<br />'; //Give error message if he dosent
- }
- if(strlen($username) < 5) //Check if length of username is less then 5
- {
- $error_message .= 'Name needs to consist of 5 characters and number or more.<br />'; // give error message if not long enough
- }
- $string_exp = "^[A-Za-z0-9]";
- if(!eregi($string_exp,$username)) //Check for invalid characters in username
- {
- $error_message .= 'The username you entered does not appear to be valid.<br />'; //Give error message if username have invalid characters
- }
- $userresult = mysql_query("SELECT * FROM User WHERE username = '$username'", $dbc); //check if the username already exist
- if(!$userresult) //
- {
- $error_message .='invalid query: ' . mysql_error() . "<br />"; //mysql error if it dosent work
- }
- $num_rows_user = mysql_num_rows($userresult); //check how many rows it found
- if(!$num_rows_user == 0) //if the num of rows is not 0 then give error
- {
- $error_message .= 'The username is already taken <br />'; //Error message
- }
- $emailresult = mysql_query("SELECT * FROM User WHERE username = '$email'", $dbc); //Check if email already exist
- if(!$emailresult) //
- {
- $error_message .='invalid query: ' . mysql_error() . "<br />"; //Mysql error if it dosent work
- }
- $num_rows_user = mysql_num_rows($emailresult); //check how many rows it fund
- if(!$num_rows_user == 0) //if num of rows is not 0 then give error
- {
- $error_message .= 'The Email is already taken <br />'; //error message
- }
- if($email != $email_confirm) //check if email and email confirm is equal
- {
- $error_message .= 'The Emails do not match <br />'; //error message
- }
- if(strlen($error_message) > 0) //If there where no errors then....
- {
- died($error_message);
- }
- echo "It worked!"
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement