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

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $client_name = $_POST["client_name"];
    $email = $_POST["email"];
    $phone_number = $_POST["phone_number"];
    $address = $_POST["address"];
    $state = $_POST["state"];
    $company = $_POST["company"];

    // You can set the start_date to the current date and time using PHP
    $start_date = date('Y-m-d H:i:s');

    // Insert the data into the database
    $sql = "INSERT INTO clients (client_name, email, phone_number, address, state, company, start_date)
            VALUES ('$client_name', '$email', '$phone_number', '$address', '$state', '$company', '$start_date')";

    if (mysqli_query($conn, $sql)) {
        // Redirect to all_clients.php
        header("Location: all_clients.php");
        exit(); // Ensure that no other code executes after the redirect
    } else {
        echo "Error: " . $sql . "<br>" . mysqli_error($conn);
    }

    // Close the database connection
    mysqli_close($conn);
} else {
    echo "Invalid request method";
}
?>
