Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>Log In | Subject Choice</title>
- </head>
- <body>
- <h1>Log In Below:</h1>
- <p>If you don't have an account <a href="index.php">create one here</a>.</p>
- <form method="POST" action="login.php">
- User <br><input type="text" name="username" size="40"><br>
- Password <br><input type="password" name="password" size="40"><br>
- <input id="button" type="submit" name="submit" value="Log-In"> </form>
- <?php
- if(!empty($_POST['username'])) //only query the database once username has been submitted
- {
- $mysqli = new mysqli($HOST, $USER, $PASS, $NAME);
- if ($mysqli->connect_errno) {
- echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>";
- exit();
- }
- $username = $_POST['username'];
- $password = $_POST['password'];
- $sql = "SELECT * from userdata WHERE username = '{$username}' AND password = '{$password}' LIMIT 1";
- $result = $mysqli->query($sql);
- if ($result->num_rows == 0) {
- echo "<p>Incorrect Username/Password.</p>";
- } else {
- echo "<p>Logged in successfully</p>
- $sql = "SELECT subject1, subject2, subject3 FROM userdata WHERE username = '{$username}'";
- if ($result->num_rows > 0) {
- while($row = $result->fetch_assoc()) {
- 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>";
- }
- } else {
- echo "0 results";
- }
- }
- }
- ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment