Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. <?php
  2. include 'connect.php';
  3. include 'header.php';
  4.  
  5. echo '<h3>Sign up</h3>';
  6.  
  7. if($_SERVER['REQUEST_METHOD'] != 'POST')
  8. {
  9.  
  10. echo '<form method="post" action="">
  11. Username: <input type="text" name="user_name" /><br/>
  12.  
  13. Password: <input type="password" name="user_pass"><br/>
  14. Password again: <input type="password" name="user_pass_check"><br/>
  15. E-mail: <input type="email" name="user_email"><br/>
  16. <input type="submit" value="Register" />
  17. <br/>
  18. </form>';
  19. }
  20. else
  21. {
  22.  
  23.  
  24. $errors = array();
  25.  
  26. if(isset($_POST['user_name']))
  27. {
  28. //the user name exists
  29. if(!ctype_alnum($_POST['user_name']))
  30. {
  31. $errors[] = 'The username can only contain letters and digits.';
  32. }
  33. if(strlen($_POST['user_name']) > 30)
  34. {
  35. $errors[] = 'The username cannot be longer than 30 characters.';
  36. }
  37. }
  38. else
  39. {
  40. $errors[] = 'The username field must not be empty.';
  41. }
  42.  
  43.  
  44. if(isset($_POST['user_pass']))
  45. {
  46. if($_POST['user_pass'] != $_POST['user_pass_check'])
  47. {
  48. $errors[] = 'The two passwords did not match.';
  49. }
  50. }
  51. else
  52. {
  53. $errors[] = 'The password field cannot be empty.';
  54. }
  55.  
  56. if(!empty($errors))
  57. {
  58. echo 'Uh-oh.. a couple of fields are not filled in correctly..';
  59. echo '<ul>';
  60. foreach($errors as $key => $value)
  61. {
  62. echo '<li>' . $value . '</li>';
  63. }
  64. echo '</ul>';
  65. }
  66. else
  67. {
  68.  
  69. $sql = "INSERT INTO
  70. users(user_name, user_pass, user_email ,user_date, user_level)
  71. VALUES('" . mysqli_real_escape_string($con,$_POST['user_name']) . "',
  72. '" . sha1($_POST['user_pass']) . "',
  73. '" . mysqli_real_escape_string($con,$_POST['user_email']) . "',
  74. NOW(),
  75. 0)";
  76.  
  77. $result = mysqli_query($con,$sql);
  78. if(!$result)
  79. {
  80.  
  81. echo 'Something went wrong while registering. Please try again later.';
  82.  
  83. }
  84. else
  85. {
  86. echo 'Successfully registered. You can now <a href="signin.php">sign in</a> and start posting! :-)';
  87. }
  88. }
  89. }
  90.  
  91. include 'footer.php';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement