<?php 

// ----------------------------
// SIGNUP PROCESS
// ----------------------------
if (isset($_POST['signupBtn'])) {

    $fullName    = mysqli_real_escape_string($conn, $_POST['full_name']);
    $email       = mysqli_real_escape_string($conn, $_POST['email']);
    $phone       = mysqli_real_escape_string($conn, $_POST['phone']);
    $address     = mysqli_real_escape_string($conn, $_POST['address']);
    $dob         = mysqli_real_escape_string($conn, $_POST['dob']);
    $gender      = mysqli_real_escape_string($conn, $_POST['gender']);
    $nationality = mysqli_real_escape_string($conn, $_POST['nationality']);
    $kyc_status  = "Verified";
    $password    = mysqli_real_escape_string($conn, $_POST['password']);

    // Hash password
    $hashedPass = password_hash($password, PASSWORD_DEFAULT);

    // GENERATE ACCOUNT NUMBER (example: 10 digits)
    $account_number = rand(1000000000, 9999999999);

    // Insert query
    $sql = "INSERT INTO users (
        full_name, email, phone, password, account_number, account_balance,
        address, date_of_birth, gender, nationality, kyc_status
    ) VALUES (
        '$fullName', '$email', '$phone', '$hashedPass', '$account_number', 0.00,
        '$address', '$dob', '$gender', '$nationality', '$kyc_status'
    )";

    $result = mysqli_query($conn, $sql);

    if ($result) {
        echo "<script>alert('Signup successful!');</script>";
    } else {
        echo "<script>alert('Signup failed: " . mysqli_error($conn) . "');</script>";
    }
}

mysqli_close($conn);
?>