Guest User

Untitled

a guest
Dec 10th, 2017
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. <?php
  2.  
  3. // this page checks if a username is taken , checks if a email is vailid then sends a confirmation email into it
  4.  
  5. $email = $_POST['email'];
  6. $username = $_POST['username'];
  7. $password2 = $_POST['password'];
  8. $password = sha1($password2);
  9. $confirm_password = $_POST['confirm_password'];
  10.  
  11. $error_email = "";
  12. $error_username = "";
  13. $error_username2 = "";
  14. $error_password = "";
  15.  
  16. if($password2 !== $confirm_password){
  17.  
  18. $error_password = "Passwords didn't match";
  19.  
  20.  
  21.  
  22. }
  23.  
  24. if (!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)){
  25. $error_email = "invalid email , please try again";
  26.  
  27. } else {
  28.  
  29. $to = $email;
  30. $subject = "Thank you for registering on my website!";
  31.  
  32. // please add your website name in the line below
  33. $message = "You recently registered on my website which is called: ";
  34.  
  35. mail($to , $subject , $message);
  36.  
  37. }
  38.  
  39.  
  40. //you may have to edit some of this , but thats on you, email me at jdbchamp@comcast.net if you need help
  41.  
  42. $host = "localhost";
  43. $username = "root";
  44. $password = "";
  45. $my_db = "test";
  46.  
  47. $sql = mysqli($host ,$username ,$password ,$my_db);
  48.  
  49. $username = $sql->real_escape_string($username);
  50. $password = $sql->real_escape_string($password);
  51. $email = $sql->real_escape_string($email);
  52.  
  53. $query = "SELECT * FROM test_table WHERE username='$username'";
  54. $result = $sql->query($query) or die($query.'<br />'.$sql->error);
  55.  
  56. if ($result->num_rows > 0) {
  57. // already exists
  58. } else {
  59. //doesnt exist
  60. }
  61.  
  62. $query = "INSERT INTO test_table (email , username , password) VALUES ('$email', '$username', '$password')";
  63. $result = $sql->query($query) or die($query.'<br />'.$sql->error);
  64.  
  65.  
  66. if($error_email && $error_username && $error_username2 && $error_password !== ""){
  67.  
  68. header("Location: error.php");
  69.  
  70. echo "There was an error or maybe more please go back and fix them" . "<br />";
  71. echo $error_email . "<br />";
  72. echo $error_username . "<br />";
  73. echo $error_username2 . "<br />";
  74. echo $error_password . "<br />";
  75.  
  76.  
  77. } else {
  78.  
  79. header("Location: success.php");
  80.  
  81.  
  82. }
Add Comment
Please, Sign In to add comment