Guest User

Untitled

a guest
Jan 4th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>Log In | Subject Choice</title>
  4. </head>
  5. <body>
  6. <h1>Log In Below:</h1>
  7. <p>If you don't have an account <a href="index.php">create one here</a>.</p>
  8.  
  9. <form method="POST" action="login.php">
  10. User <br><input type="text" name="username" size="40"><br>
  11. Password <br><input type="password" name="password" size="40"><br>
  12. <input id="button" type="submit" name="submit" value="Log-In"> </form>
  13.  
  14. <?php
  15. if(!empty($_POST['username'])) //only query the database once username has been submitted
  16.  
  17. {
  18. $mysqli = new mysqli($HOST, $USER, $PASS, $NAME);
  19. if ($mysqli->connect_errno) {
  20. echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>";
  21. exit();
  22. }
  23.  
  24. $username = $_POST['username'];
  25. $password = $_POST['password'];
  26.  
  27. $sql = "SELECT * from userdata WHERE username = '{$username}' AND password = '{$password}' LIMIT 1";
  28.  
  29. $result = $mysqli->query($sql);
  30. if ($result->num_rows == 0) {
  31. echo "<p>Incorrect Username/Password.</p>";
  32. } else {
  33. echo "<p>Logged in successfully</p>
  34.  
  35.  
  36. $sql = "SELECT subject1, subject2, subject3 FROM userdata WHERE username = '{$username}'";
  37.  
  38. if ($result->num_rows > 0) {
  39. while($row = $result->fetch_assoc()) {
  40. echo "<b>First Subject Choice: </b>" . $row["subject1"]. "<br><b>Second Subject Choice: </b>" . $row["subject2"]. "<br><b>Third Subject Choice </b>" . $row["subject3"]. "<br>";
  41. }
  42.  
  43. } else {
  44. echo "0 results";
  45. }
  46.  
  47. }
  48. }
  49. ?>
  50. </body>
  51. </html>
Add Comment
Please, Sign In to add comment