Advertisement
Guest User

Untitled

a guest
Aug 10th, 2016
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. <?php
  2. session_start();
  3. // connect to database
  4. // Check connection
  5. $db = mysqli_connect("localhost", "admin", "password", "authentication");
  6. if (isset($_POST['register_btn'])) {
  7. $username = mysql_real_escape_string($_POST['username']);
  8. $email = mysql_real_escape_string($_POST['email']);
  9. $password = mysql_real_escape_string($_POST['password']);
  10. $password2 = mysql_real_escape_string($_POST['password2']);
  11. if ($password == $password2) {
  12. // create user
  13. $password = md5($password); //hash password before storing for security purposes
  14. $sql = "INSERT INTO users(username, email, password) VALUES('$username', '$email', '$password')";
  15. mysqli_query($db, $sql);
  16. $_SESSION['message'] = "You are now logged in";
  17. $_SESSION['username'] = $username;
  18. header("location: home.php"); //redirect to home page
  19. }else{
  20. $_SESSION['message'] = "The two passwords do not match";
  21. }
  22. }
  23. ?>
  24.  
  25.  
  26.  
  27. <!DOCTYPE html>
  28. <html>
  29. <head>
  30. <title>Register, login and logout user php mysql</title>
  31. <link rel="stylesheet" type="text/css" href="style.css">
  32. </head>
  33. <body>
  34. <div class="header">
  35. <h1>Register, login and logout user php mysql</h1>
  36. </div>
  37.  
  38. <?php
  39. if (isset($_SESSION['message'])) {
  40. echo "<div id='error_msg'>".$_SESSION['message']."</div>";
  41. unset($_SESSION['message']);
  42. }
  43. ?>
  44.  
  45. <form method="post" action="register.php">
  46. <table>
  47. <tr>
  48. <td>Username:</td>
  49. <td><input type="text" name="username" class="textInput"></td>
  50. </tr>
  51. <tr>
  52. <td>Email:</td>
  53. <td><input type="email" name="email" class="textInput"></td>
  54. </tr>
  55. <tr>
  56. <td>Password:</td>
  57. <td><input type="password" name="password" class="textInput"></td>
  58. </tr>
  59. <tr>
  60. <td>Password again:</td>
  61. <td><input type="password" name="password2" class="textInput"></td>
  62. </tr>
  63. <tr>
  64. <td></td>
  65. <td><input type="submit" name="register_btn" value="Register"></td>
  66. </tr>
  67. </table>
  68. </form>
  69. </body>
  70. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement