Guest User

Untitled

a guest
Dec 19th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. // variable declaration
  2. $username = "";
  3. $email = "";
  4. $errors = array();
  5. $_SESSION['success'] = "";
  6.  
  7. // connect to database
  8. $db = mysqli_connect('localhost', 'root', '', 'registration');
  9.  
  10. // REGISTER USER
  11. if (isset($_POST['reg_user'])) {
  12. // receive all input values from the form
  13. $title = mysqli_real_escape_string($db, $_POST['title']);
  14. $firstname = mysqli_real_escape_string($db, $_POST['firstname']);
  15. $lastname = mysqli_real_escape_string($db, $_POST['lastname']);
  16. $code = mysqli_real_escape_string($db, $_POST['code']);
  17. $mobile = mysqli_real_escape_string($db, $_POST['mobile']);
  18. $username = mysqli_real_escape_string($db, $_POST['username']);
  19. $email = mysqli_real_escape_string($db, $_POST['email']);
  20. $password_1 = mysqli_real_escape_string($db, $_POST['password_1']);
  21. $password_2 = mysqli_real_escape_string($db, $_POST['password_2']);
  22.  
  23. // form validation: ensure that the form is correctly filled
  24. if (empty($username)) { array_push($errors, "Username is required"); }
  25. if (empty($email)) { array_push($errors, "Email is required"); }
  26. if (empty($password_1)) { array_push($errors, "Password is required"); }
  27.  
  28. if ($password_1 != $password_2) {
  29. array_push($errors, "The two passwords do not match");
  30. }
  31. $query = mysql_query("SELECT * FROM user3 WHERE email='$email'");
  32. if(mysql_num_rows($query) > 0 ) { //check if there is already an entry for that username
  33. echo "email already exists!";
  34. }else{ echo"login";
  35. }
  36.  
  37.  
  38. // register user if there are no errors in the form
  39. if (count($errors) == 0) {
  40. $password = md5($password_1);//encrypt the password before saving in the database
  41. $query = "INSERT INTO user3 (title,firstname,lastname,code,mobile,username, email, password)
  42. VALUES('$title','$firstname','$lastname','$code','$mobile','$username', '$email', '$password')";
  43. mysqli_query($db, $query);
  44.  
  45. $_SESSION['email'] = $email;
  46. $_SESSION['success'] = "You are now logged in";
  47. $_SESSION['mobile']=$mobile;
  48. header('location: index.php');
  49. }
  50.  
  51. }
Add Comment
Please, Sign In to add comment