Advertisement
Guest User

Untitled

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