Advertisement
Guest User

daniel is gay

a guest
May 24th, 2017
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. if (array_key_exists("newuser", $_POST))
  2. {
  3. registerNewUser($_POST["username"], $_POST["password"]);
  4. }
  5. else
  6. {
  7. loginUser($_POST["username"], $_POST["password"]);
  8. }
  9.  
  10. function registerNewUser($user, $pass)
  11. {
  12. global $conn;
  13.  
  14. $cmd = "SELECT * FROM `simpleuser` WHERE `username` = '$user'";
  15. $result = $conn->prepare($cmd);
  16. $result->execute();
  17.  
  18. if ($result->rowCount() > 0)
  19. {
  20. displayMessage("That username already exists.");
  21. }
  22. else
  23. {
  24. $cmd = "INSERT INTO `simpleuser` VALUES ('$user', '$pass')";
  25. echo $cmd."<br />";
  26. $result = $conn->prepare($cmd);
  27. $result->execute();
  28. displayMessage("User successfully added.");
  29. }
  30. }
  31.  
  32. function loginUser($user, $pass)
  33. {
  34. global $conn;
  35.  
  36. $cmd = "SELECT `password` FROM `simpleuser` WHERE `username` = '$user'";
  37. $result = $conn->prepare($cmd);
  38. $result->execute();
  39.  
  40. if ($result->rowCount() == 0)
  41. {
  42. displayMessage("Username or password is incorrect");
  43. }
  44. else
  45. {
  46. $data = $result->fetch();
  47. if ($data["password"] == $pass)
  48. {
  49. displayMessage("Welcome back, $user!");
  50. }
  51. else
  52. {
  53. displayMessage("Username or password is incorrect");
  54. }
  55. }
  56. }
  57.  
  58. function displayMessage($msg)
  59. {
  60. echo "$msg<br/>";
  61. echo "<a href = 'index.php' >Go Home</a>";
  62. }
  63. ?>
  64. <html>
  65. <head>
  66. <title></title>
  67. <style>
  68. input
  69. {
  70. margin: 10px 10px;
  71. }
  72. </style>
  73. <script>
  74. function initialize()
  75. {
  76.  
  77. }
  78. </script>
  79. </head>
  80. <body onload = "initialize();">
  81. <form method = "post" action = "register.php">
  82. Username: <input type = "text" name = "username"/>
  83. Password: <input type = "text" name = "password"/>
  84. New User? <input type = "checkbox" name = "newuser" />
  85. <input type = "submit" value = "Login"/>
  86. </form>
  87. </body>
  88. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement