<?php require'includes/head2.php';


	if(isset($_POST['add']))
	{	
		
		
		$n=$_POST['p_name'];
		$d=$_POST['p_date'];
		$p=$_POST['pay'];
		$get_id="select `p_id` from `patient` where `p_name`='$n'";
		$get_id_res = $conn->query($get_id);
		$row=mysqli_fetch_array($get_id_res);
		$p_id=$row['p_id'];
		
			
				 $insert_country="insert into `appointment`(`p_id`,`date`,`payment`)VALUES('$p_id','$d','$p')";
				$result = $conn->query($insert_country);
				
				echo "<script type='text/javascript'>window.location.href = 'home.php'</script>";
			
		
	}
?>

<br>
	<form action="" method="POST" enctype="multipart/form-data"  id="appointmentForm">
		<input style="font-size:20pt;width:12em; background-color:#ffffff; border-style:none" type="text" name="p_name" placeholder="Name" id="tag" required><br><br>
		<input style="font-size:20pt;width:12em; background-color:#ffffff; border-style:none" type="date" name="p_date" placeholder="Date" required><br><br>
		<font style="font-size:18pt">Not Payed:<input type="radio" name="pay" value=0 checked> | Payed:<input type="radio" name="pay" value=1></font><br><br>
<input type="submit" name="add" value="ADD" id="submitBtn" style="font-size:20pt;width:12em; background-color:#000000; color:#ffffff; border-style:none">
	</form>
	
<script>
    const form = document.getElementById('appointmentForm');
    const submitBtn = document.getElementById('submitBtn');
    
    form.addEventListener('submit', function(e){
        
        setTimeout(() => {
            submitBtn.disabled = true;
        }, 1); 
    });
</script>

<?php



require 'includes/foot.php';?>