Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1.  
  2. //This code runs if the form has been submitted
  3. if (isset($_POST['submit'])) {
  4.  
  5. //This makes sure they did not leave any fields blank
  6. if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) {
  7. die('You did not complete all of the required fields');
  8. }
  9.  
  10. // checks if the username is in use
  11. if (!get_magic_quotes_gpc()) {
  12. $_POST['username'] = addslashes($_POST['username']);
  13. }
  14. $usercheck = $_POST['username'];
  15. $check = mysql_query("SELECT username FROM signup WHERE username = '$usercheck'")
  16. or die(mysql_error());
  17. $check2 = mysql_num_rows($check);
  18.  
  19. //if the name exists it gives an error
  20. if ($check2 != 0) {
  21. die('Sorry, the username '.$_POST['username'].' is already in use.');
  22. }
  23.  
  24. // this makes sure both passwords entered match
  25. if ($_POST['pass'] != $_POST['pass2']) {
  26. die('Your passwords did not match. ');
  27. }
  28.  
  29. // here we encrypt the password and add slashes if needed
  30. if (!get_magic_quotes_gpc()) {
  31. $_POST['pass'] = addslashes($_POST['pass']);
  32. $_POST['username'] = addslashes($_POST['username']);
  33. }
  34.  
  35. // now we insert it into the database
  36. $insert = "INSERT INTO signup (username, password)
  37. VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
  38. $add_member = mysql_query($insert);
  39. ?>
  40.  
  41.  
  42. <h1>Registered</h1>
  43. <p>Thank you, new user added</a>.</p>
  44.  
  45.  
  46. <?php
  47. }
  48. else
  49. {
  50. ?>
  51.  
  52.  
  53. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  54. <table border="0">
  55. <tr><td>Username:</td><td>
  56. <input type="text" name="username" maxlength="60">
  57. </td></tr>
  58. <tr><td>Password:</td><td>
  59. <input type="password" name="pass" maxlength="10">
  60. </td></tr>
  61. <tr><td>Confirm Password:</td><td>
  62. <input type="password" name="pass2" maxlength="10">
  63. </td></tr>
  64. <tr><th colspan=2><input type="submit" name="submit" value="Add user"></th></tr> </table>
  65. </form>
  66.  
  67. <?php
  68. }
  69. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement