<?php
// Include the database connection file
include('database.php');

// Check if the required POST data is set
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Get data from the AJAX request
    $qz1 = isset($_POST['qz1']) ? mysqli_real_escape_string($conn, $_POST['qz1']) : '';
    $qz2 = isset($_POST['qz2']) ? mysqli_real_escape_string($conn, $_POST['qz2']) : '';
    $qz3 = isset($_POST['qz3']) ? mysqli_real_escape_string($conn, $_POST['qz3']) : '';
    $co3 = isset($_POST['co3']) ? mysqli_real_escape_string($conn, $_POST['co3']) : '';
    $qz4 = isset($_POST['qz4']) ? mysqli_real_escape_string($conn, $_POST['qz4']) : '';
    $qz5 = isset($_POST['qz5']) ? mysqli_real_escape_string($conn, $_POST['qz5']) : '';
    $qz6 = isset($_POST['qz6']) ? mysqli_real_escape_string($conn, $_POST['qz6']) : '';
    $qz7 = isset($_POST['qz7']) ? mysqli_real_escape_string($conn, $_POST['qz7']) : '';
    $name = isset($_POST['name']) ? mysqli_real_escape_string($conn, $_POST['name']) : '';

    // Prepare the SQL query to insert data into the database
    $sql = "INSERT INTO betco (qz_1, qz_2, qz_3, co_3, qz_4, qz_5, qz_6, qz_7, name) 
            VALUES ('$qz1', '$qz2', '$qz3', '$co3', '$qz4', '$qz5', '$qz6', '$qz7', '$name')";

    // Execute the query
    if (mysqli_query($conn, $sql)) {
        // Return success response
        echo "Data has been successfully saved!";
    } else {
        // Return error message
        echo "Error: " . $sql . "<br>" . mysqli_error($conn);
    }

    // Close the database connection
    mysqli_close($conn);
} else {
    // If not a POST request, return an error message
    echo "Invalid request method.";
}
?>
