<?php
session_start();
$con = mysqli_connect("localhost", "root", "", "WSAS");

if (!$con) {
    die("Connection failed: " . mysqli_connect_error());
}

$email = $_POST['email'];
$password = $_POST['password']; 

$stmt = mysqli_prepare($con, "SELECT * FROM student_login WHERE email = ?");
mysqli_stmt_bind_param($stmt, "s", $email);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$user = mysqli_fetch_assoc($result);

if (!$query) {
    die("Query failed: " . mysqli_error($con));
}

$user = mysqli_fetch_assoc($query);

if ($user && password_verify($password, $user['password'])) { 
    $_SESSION['login_id'] = $user['id'];
    header("Location: ../studentpanel/Student_Dashboard.php");
    exit();
} else {
    echo "<script>alert('Invalid email or password'); window.location.href='login.php';</script>";
}
?>