Guest User

Untitled

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