Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.32 KB | None | 0 0
  1. <?php
  2.     include('connect.php');
  3.    
  4. function died($error)
  5. {
  6.     echo "Error: <br /><br />";
  7.     echo $error."<br /><br />";
  8.     die();
  9. }
  10.  
  11. //Variables
  12. $name = $_POST[name];
  13. $email = $_POST[email];
  14. $email_confirm = $_POST[email_confirm];
  15. $username = $_POST[username];
  16. $password = $_POST[password];
  17. $password_confirm = $_POST[password_confirm];
  18. //end of variables
  19.  
  20. if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['email_confirm']) || !isset($_POST['username']) || !isset($_POST['password']) || !isset($_POST['password_confirm']))
  21. {
  22.     died('It appears that you did not enter all the required information');
  23. }
  24.  
  25.  
  26.  
  27. $error_message = "";
  28. $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";                     //Define witch characters are ok
  29. if(!eregi($email_exp,$email))                                               //Check for invalid characters in email
  30. {
  31.     $error_message .= 'The Email Address you entered does not appear to be valid.<br />';  //give error message is characters in email is invalid
  32. }
  33.  
  34. $string_exp = "^[a-z .'-]+$";                                                        //Definte what is ok to have in your name
  35. if(!eregi($string_exp,$name))                                                        //check if the user has valid characters in his name
  36. {
  37.     $error_message .= 'The Name you entered does not appear to be valid.<br />';     //Give error message if he dosent
  38. }
  39.  
  40. if(strlen($username) < 5)                                                                 //Check if length of username is less then 5
  41. {
  42.     $error_message .= 'Name needs to consist of 5 characters and number or more.<br />';    // give error message if not long enough
  43. }
  44. $string_exp = "^[A-Za-z0-9]";
  45. if(!eregi($string_exp,$username))                                                //Check for invalid characters in username
  46. {                                                                                          
  47.     $error_message .= 'The username you entered does not appear to be valid.<br />'; //Give error message if username have invalid characters
  48. }
  49.  
  50. $userresult = mysql_query("SELECT * FROM User WHERE username = '$username'", $dbc);      //check if the username already exist
  51. if(!$userresult)                                                                         //
  52. {
  53.     $error_message .='invalid query: ' . mysql_error() . "<br />";                      //mysql error if it dosent work
  54. }
  55. $num_rows_user = mysql_num_rows($userresult);                                           //check how many rows it found
  56. if(!$num_rows_user == 0)                                                                //if the num of rows is not 0 then give error
  57. {
  58.     $error_message .= 'The username is already taken <br />';                           //Error message
  59. }
  60.  
  61. $emailresult = mysql_query("SELECT * FROM User WHERE username = '$email'", $dbc);       //Check if email already exist
  62. if(!$emailresult)                                                                       //
  63. {
  64.     $error_message .='invalid query: ' . mysql_error() . "<br />";                      //Mysql error if it dosent work
  65. }
  66. $num_rows_user = mysql_num_rows($emailresult);                                          //check how many rows it fund
  67. if(!$num_rows_user == 0)                                                                //if num of rows is not 0 then give error
  68. {
  69.     $error_message .= 'The Email is already taken <br />';                              //error message
  70. }                                              
  71. if($email != $email_confirm)                                                            //check if email and email confirm is equal
  72. {
  73.     $error_message .= 'The Emails do not match <br />';                                 //error message
  74. }
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. if(strlen($error_message) > 0)                                                          //If there where no errors then....
  83. {
  84. died($error_message);
  85. }
  86.  
  87. echo "It worked!"
  88. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement