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

include(__DIR__ . '/connect.php');

if($connect->connect_error){
    die("DB connection not working");
}

if(isset($_POST['patient_name'])){

    $name = $_POST['patient_name'];
    $phone = $_POST['phone'];
    $doctor = $_POST['doctor_id'];
    $date = $_POST['date'];
    $time = $_POST['time'];

    $status = "pending";

    $sql = "INSERT INTO appointments 
    (patient_name, phone, doctor_id, date, time, status)
    VALUES ('$name','$phone','$doctor','$date','$time','$status')";

    if($connect->query($sql)){
        header("Location: index.php?success=1");
        exit();
    }else{
        die("Query Error: " . $connect->error);
    }
}
?>