Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- if(isset($_POST)){
- //make connection
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "exam";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- if((isset($_POST['username']) && !empty($_POST['username'])) && (isset($_POST['password']) && !empty($_POST['password']))){
- $username = trim(htmlspecialchars($_POST['username']));
- $password = md5(trim($_POST['password']));
- $query = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";
- $row = $conn->query($query);
- if($fetch = $row->num_rows == 1){
- $guka = $row->fetch_assoc();
- $_SESSION['username'] = $guka['username'];
- $_SESSION['password'] = $guka['password'];
- print_r($_SESSION);
- }else{
- echo "incorrect password";
- }
- }
- $conn->close();
- }
- ?>
- <!DOCTYPE html>
- <html lang="en" dir="ltr">
- <head>
- <meta charset="utf-8">
- <title></title>
- </head>
- <body>
- <form class="" method="post">
- <input type="text" name="username" placeholder="username">
- <input type="password" name="password" placeholder="password">
- <input type="submit" name="" value="submit">
- </form>
- <?php
- if(isset($_SESSION)){
- echo $_SESSION['username'];
- }
- ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment