logincode

 <?php

session_start();

include('dbconfig.php');


if(isset($_POST['login_button']))

{

    $email = mysqli_real_escape_string($conn, $_POST['email']);

    $password = mysqli_real_escape_string($conn, $_POST['password']);


    $query = "SELECT * FROM users where email='$email' and password='$password' LIMIT 1";

    $query_run = mysqli_query($conn, $query);


    if(mysqli_num_rows($query_run) > 0)

    {

        $row = mysqli_fetch_array($query_run);


        // Authenticating Logged In User

        $_SESSION['authentication'] = true;


        // Storing Authenticated User data in Session

        $_SESSION['auth_user'] = [

            'user_id'=>$row['id'],

            'user_fullname'=>$row['fname'],

            'user_email'=>$row['email'],

        ];


        $_SESSION['message'] = "You are Logged In Successfully"; //message to show

        header("Location: index.php");

        

    }

    else

    {

        $_SESSION['message'] = "Invalid Email or Password"; //message to show

        header("Location: index.php");

        exit(0);

    }

}

?>

Comments