Guest User

Untitled

a guest
Nov 1st, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. <?php
  2. // Change this to your connection info.
  3. include('mysqli_connect.php');
  4.  
  5. // Now we check if the data was submitted, isset will check if the data exists.
  6. if (!isset($_POST['username'], $_POST['password'], $_POST['email'])) {
  7. // Could not get the data that should have been sent.
  8. die ('<script>alert("ERROR ID: R#1");location.href="../index.php";</script>');
  9. }
  10. // Make sure the submitted registration values are not empty.
  11. if (empty($_POST['username']) || empty($_POST['password']) || empty($_POST['email'])) {
  12. // One or more values are empty...
  13. die ('<script>alert("ERROR ID: R#2");location.href="../index.php";</script>');
  14. }
  15. // We need to check if the account with that username exists
  16. if ($stmt = $mysqli_web->prepare('SELECT id, password FROM user WHERE username = ?')) {
  17. // Bind parameters (s = string, i = int, b = blob, etc), hash the password using the PHP password_hash function.
  18. $stmt->bind_param('s', $_POST['username']);
  19. $stmt->execute();
  20. $stmt->store_result();
  21. // Store the result so we can check if the account exists in the database.
  22. if ($stmt->num_rows > 0) {
  23. // Username already exists
  24. echo 'Username exists, please choose another!<br><a href="index.php">Back</a>';
  25. } else {
  26. // Username doesnt exists, insert new account
  27. if ($stmt = $mysqli_web->prepare('INSERT INTO user (username, password, email) VALUES (?, ?, ?)')) {
  28. // We do not want to expose passwords in our database, so hash the password and use password_verify when a user logs in.
  29. //date_default_timezone_set('Europe/Stockholm');
  30. //$date = date("Y/m/d");
  31. $password = password_hash($_POST['pass'], PASSWORD_DEFAULT);
  32. $stmt->bind_param('ssss', $_POST['username'], $password, $_POST['email']);
  33. $stmt->execute();
  34. echo 'You have successfully registered, you can now login!<br><a href="index.php">Login</a>';
  35. } else {
  36. echo 'Could not prepare statement!1';
  37. //echo error_reporting(E_ALL);
  38. }
  39. }
  40. $stmt->close();
  41. } else {
  42. echo 'Could not prepare statement!2';
  43. }
  44. $mysqli_web->close();
  45.  
  46.  
  47. ?>
  48.  
  49. <?php
  50. // Enter your Host, username, password, database below.
  51. // I left password empty because i do not set password on localhost.
  52. $mysqli_web = mysqli_connect("localhost","root","mypass","web_wan");
  53. $mysqli_hub = mysqli_connect("localhost","root","mypass","hub");
  54. $mysqli_0001 = mysqli_connect("localhost","root","mypass","mugame_0001");
  55. // Check connection
  56. if (mysqli_connect_errno())
  57. {
  58. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  59. }
  60. ?>
  61.  
  62. <form class="nk-sign-form-register" action="php/mysqli_action.php" method="post">
  63. <input class="form-control" type="text" name="username" placeholder="Username" required>
  64. <div class="nk-gap-2"></div>
  65.  
  66. <input class="form-control" type="email" name="email" placeholder="Email" required>
  67. <div class="nk-gap-2"></div>
  68.  
  69. <input class="form-control" type="text" name="password" placeholder="Password" required>
  70. <div class="nk-gap-2"></div>
  71.  
  72. <div class="float-left">A password will be emailed to you.</div>
  73. <button class="nk-btn nk-btn-color-white link-effect-4 float-right" name="doreg">Register</button>
  74. </form>
Add Comment
Please, Sign In to add comment