<?php


session_start(); 
    $u_uname = '';
    if (isset($_COOKIE['auth_token']))
    {
        $u_uname = $_COOKIE['auth_token'];
    }else{
        header("location:../login.php");
    }
    
include '../include/connection.php';

// Check if all required parameters are set
if (isset($_POST['name'], $_POST['email'], $_POST['mobile'], $_POST['whats'], $_POST['address'], $_POST['company'], $_POST['dob'], $_POST['gender'])) {
    // Assign values to variables
    $name = $_POST['name'];
    $email = $_POST['email'];
    $mobile = $_POST['mobile'];
    $whats = $_POST['whats'];
    $address = $_POST['address'];
    $company = $_POST['company'];
    $dob = $_POST['dob'];
    $gender = $_POST['gender'];
    
    
     $randomNumber = sprintf("%06d", mt_rand(1, 999999));

    // Construct the unique ID
    $uniqueID = "CSH" . $randomNumber;

    // SQL query
    $sql = "INSERT INTO `clientRegister`(`client_id`, `full_name`, `email`, `mobile_no`,`whatsapp`, `address`, `company_name`, `dob`, `gender`) 
    VALUES ('$uniqueID', '$name', '$email', '$mobile' ,'$whats','$address','$company','$dob','$gender')";

    // Execute the query
    if ($link->query($sql) === TRUE) {
        header('Location:../addClient.php?status=1');
    } else {
        echo "Error: " . $sql . "<br>" . $link->error;
    }
} else {
    // Handle case where parameters are missing
    echo "Error: Missing parameters";
}
?>
