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

$fname = $_POST['fname'] ?? '';
$lname = $_POST['lname'] ?? '';
$conno = $_POST['conno'] ?? '';
$email = strtolower($_POST['uemail']) ?? '';
$pass = md5($_POST['pass'] ?? '');
$otp  = $_POST['otp'] ?? '';
$is_verified = isset($_POST['is_verified']) ? intval($_POST['is_verified']) : 0;

$sql = "INSERT INTO tblcred (fname, lname, conno, email, pass, otp_code, is_verified)
        VALUES ('$fname', '$lname', '$conno', '$email', '$pass', '$otp', $is_verified)";

if ($conn->query($sql) === TRUE) {
    echo json_encode(array("success" => true));
} else {
    echo json_encode(array("success" => false, "error" => $conn->error));
}
