Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <body>
- Log in:<br/>
- <form action="create_session.php" method="POST">
- Username: <input type="text" id="username" name="username"><br>
- Password: <input type="password" id="password" name="password"><br>
- <input type="submit" value="Login" name="login" />
- </form>
- </body>
- </html>
- <?php
- session_start();
- if($_SERVER["REQUEST_METHOD"] == "POST")
- {
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "users";
- $conn = new mysqli($servername, $username, $password, $dbname); //create connection
- // Check connection
- if ($conn->connect_error)
- {
- die("Connection failed: " . $conn->connect_error);
- }
- $myusername = mysqli_real_escape_string($conn,$_POST['username']);
- $mypassword = mysqli_real_escape_string($conn,$_POST['password']);
- //$sql = "SELECT user_type FROM users WHERE username = ? and password = ?";
- $sql = "SELECT * FROM users WHERE username = ? and password = ?";
- //$result = mysqli_query($db,$sql);
- //$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
- //$active = $row['active'];
- $stmt = $conn->prepare($sql);
- $stmt->bind_param("ss", $myusername, $mypassword);
- $stmt->execute();
- $stmt->store_result();
- $count = $stmt->num_rows;
- // $stmt->bind_result($type);
- // $count = mysqli_num_rows($result);
- //echo "type".$type, $count;
- // If result matched $myusername and $mypassword, table row must be 1 row
- $stmt->fetch();
- $stmt->close();
- $conn->close();
- if($count == 1)
- {
- //session_register("myusername");
- $_SESSION['login_user'] = $myusername;
- echo ("Login");
- //echo $type;
- /*
- if($type == 0)
- {
- header("location: student_account.php");
- }
- else
- {
- header("location: professor_account.html");
- }
- */
- }
- else
- {
- $message = "Username and/or Password incorrect.\\nTry again.";
- echo "<script type='text/javascript'>alert('$message');</script>";
- header("location: login.html");
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement