<?php
header('Content-Type: application/json');
include '../connection.php';

$email = strtolower($_POST['uemail']);
$pass = md5($_POST['pass']);

$sql = "SELECT * FROM tblcred WHERE email = '$email' AND pass = '$pass'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    $user = $result->fetch_assoc();

    // Explicit type casting to avoid type issues
    $userData = array(
        "userid"       => (int)$user['userid'],
        "fname"        => (string)$user['fname'],
        "lname"        => (string)$user['lname'],
        "conno"        => (string)$user['conno'],
        "email"        => (string)$user['email'],
        "pass"         => (string)$user['pass'],
        "otp"          => (string)$user['otp_code'],       // rename matches your DB column
        "is_verified"  => (int)$user['is_verified'],
        "usertype"     => (int)$user['usertype'],
    );

    echo json_encode(array(
        "success"   => true,
        "userData"  => $userData
    ));
} else {
    echo json_encode(array("success" => false));
}

