Advertisement
Guest User

Untitled

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