Advertisement
Guest User

Untitled

a guest
May 4th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. <?php
  2. // Connects to your Database
  3. /* DO NOT FUCKING USE ROOT!!!!!!!!!!!!! MAKE A USER FOR THIS SHIT!!!!!!!!*/
  4. $conn = mysql_connect("localhost", "root", "passwordhere") or die(mysql_error());
  5. mysql_select_db("register", $conn) or die(mysql_error());
  6.  
  7. //This code runs if the form has been submitted
  8. if (isset($_POST['submit'])) {
  9.  
  10. //This makes sure they did not leave any fields blank
  11. if (!isset($_POST['username']) || !isset($_POST['email']) || !isset($_POST['pass']) || !isset($_POST['pass2'])) {
  12. die('You did not complete all of the required fields');
  13. }
  14.  
  15. /* escape your shit or let any schmuck execute DROP MYSQL */
  16. // here we encrypt the password and add slashes if needed
  17. /* sha1 is more secure - just for the record*/
  18. $_POST['pass'] = md5($_POST['pass']);
  19. $_POST['pass'] = mysql_real_escape_string($_POST['pass']);
  20. $_POST['username'] = mysql_real_escape_string($_POST['username']);
  21. $_POST['email'] = mysql_real_escape_string($_POST['email']);
  22.  
  23. $check = mysql_query("SELECT username FROM users WHERE username = '" . $_POST['username'] . "'", $conn)
  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. // now we insert it into the database
  38. $insert = sprintf("INSERT INTO users (username, email, password) VALUES ('%s', '%s', '%s');",
  39. $_POST['username'], $_POST['email'], $_POST['pass']);
  40. $add_member = mysql_query($insert, $conn);
  41.  
  42. /* close the db */
  43. mysql_close($conn);
  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. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement