<?php
session_start();
// Database connection parameters
$host = 'localhost'; // usually 'localhost'
$dbname = 'crmsahavasco_kanakveda';
$username = 'crmsahavasco';
$password = 'sa123AWEsadfa';

include 'connection.php';
// Data to be inserted
$parent_first_name = $_POST['parent_first_name'];
$parent_last_name = $_POST['parent_last_name'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$age = $_POST['age'];
$height = $_POST['height'];
$how_to_consult = $_POST['how_to_consult'];
$email = $_POST['email'];
$mobile_no = $_POST['mobile_no'];
$city = $_POST['city'];
$monthly_program = $_POST['monthly_program'];

if($monthly_program=='20000'){
$courier_charges = "300";
}

if($monthly_program=='36000'){
$courier_charges = "600";
}

if($monthly_program=='68000'){
$courier_charges = "1200";
}


for ($i=0; $i<count($_POST['reference']);$i++) {
 $reference .= $_POST['reference'][$i];
 $reference .=","; 
}


$qry9q = "select * from  signatures_data where used_by=''";
$re9q = mysqli_query($conn,$qry9q);
while($row=mysqli_fetch_array($re9q))
{  
$signature = $row['signatures'];
$sid = $row['sid'];
}


echo $querycust = "update signatures_data set used_by='$mobile_no'  where sid = '$sid'" ;
$resultcust=mysqli_query($conn,$querycust);






// PDO connection
try {
    $pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
    die("Error: " . $e->getMessage());
}

// SQL query to insert data
echo $sql = "INSERT INTO immunity_booster_program (parent_first_name, parent_last_name, first_name, last_name, age, height, how_to_consult, reference, email, mobile_no, city, monthly_program, courier_charges, signature) VALUES (:parent_first_name, :parent_last_name, :first_name, :last_name, :age, :height, :how_to_consult, :reference, :email, :mobile_no, :city, :monthly_program, :courier_charges, :signature)";

// Prepare statement
$stmt = $pdo->prepare($sql);

// Bind parameters
$stmt->bindParam(':parent_first_name', $parent_first_name);
$stmt->bindParam(':parent_last_name', $parent_last_name);
$stmt->bindParam(':first_name', $first_name);
$stmt->bindParam(':last_name', $last_name);
$stmt->bindParam(':age', $age);
$stmt->bindParam(':height', $height);
$stmt->bindParam(':how_to_consult', $how_to_consult);
$stmt->bindParam(':reference', $reference);
$stmt->bindParam(':email', $email);
$stmt->bindParam(':mobile_no', $mobile_no);
$stmt->bindParam(':city', $city);
$stmt->bindParam(':monthly_program', $monthly_program);
$stmt->bindParam(':courier_charges', $courier_charges);
$stmt->bindParam(':signature', $signature);

// Execute statement
try {
    $stmt->execute();
    echo "Data inserted successfully.";
} catch(PDOException $e) {
    die("Error: " . $e->getMessage());
}

// Close connection
$pdo = null;

//exit();

?>
<script>
javascript:window.location.href="thank_you.html";
</script>

