<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

require 'db_conn.php';

// Use the correct POST keys
$firstname    = $_POST['firstname'] ?? '';
$lastname     = $_POST['lastname'] ?? '';
$accountname  = $_POST['accountname'] ?? '';
$email        = $_POST['email'] ?? '';
$mobileno     = $_POST['mobileno'] ?? '';
$password     = $_POST['password'] ?? '';
$confirmpass  = $_POST['confirmpass'] ?? '';
$country      = $_POST['country'] ?? '';
$country_code = $_POST['country_code'] ?? '';

// Hash password (replace MD5 later with password_hash for security)
$password_hash = md5($password);

// Insert into database
$sql = "INSERT INTO users 
        (firstname, lastname, accountname, email, mobileno, password, confirmpass, country, country_code) 
        VALUES 
        ('$firstname', '$lastname', '$accountname', '$email', '$mobileno', '$password_hash', '$confirmpass', '$country', '$country_code')";

if (mysqli_query($conn, $sql)) {
    header("Location: success.php");
    exit;
} else {
    echo "Error Occured: " . mysqli_error($conn);
}
?>
