<?php
// login.php
header("Content-Type: application/json");
$servername = "localhost";
$username = "myprojec_allytec";
$password = "allytech@2019";
$dbname = "myprojec_patient";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $data = json_decode(file_get_contents("php://input"));

    $emailid = $data->emailid;
    $password = $data->password;

    $sql = "SELECT * FROM usertbl WHERE emailid = '$emailid'";
    $result = $conn->query($sql);

    if ($result->num_rows > 0) {
        $user = $result->fetch_assoc();
        
        if ($password === $user['password']) {
            echo json_encode(['message' => 'Login successful', 'user' => $user]);
        } else {
            echo json_encode(['message' => 'Invalid credentials']);
        }
    } else {
        echo json_encode(['message' => 'User not found']);
    }
}

$conn->close();
?>
