i have a database at the links.
so the problem it still insert between the time some friends suggested to loop all the data 1st
then validate but im confused here.
**any help would be great **
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
mysql_connect("localhost","root","");
mysql_select_db("windsor_reservation");
if(isset($_POST['reserve'])){
echo $stime = ($_POST['stime']);
echo '----';
echo $etime = ($_POST['etime']);
echo '<br>';
$chk = false;
$date = date("Y-m-d");
if($stime < $etime){
$q = mysql_query("SELECT * FROM time WHERE `date`='$date' AND `stime`>='$stime' AND `etime`<='$etime'");
$count = mysql_num_rows($q);
if($count > 0){
echo 'Time already taken choose another time please';
}else{
$new_all = mysql_query("SELECT * FROM time where date='$date'");
while($get_all = mysql_fetch_assoc($new_all)){
echo $g_all_stime = $get_all['stime'];
echo "====";
echo $g_all_etime = $get_all['etime'];
echo "<br>";
if($stime == $g_all_stime && $etime == $g_all_etime){
echo 'There is already a time like yours';
$chk = false;
}
elseif($stime <= $g_all_stime && $etime >= $g_all_etime){
echo 'cannot insert the same Start and End time with server';
$chk = false;
}
elseif($stime > $g_all_stime && $etime < $g_all_etime){
echo 'the time must not be between the earlier reserve time';
$chk = false;
}
elseif($etime >= $g_all_stime && $stime <= $g_all_etime){
echo 'the end time must not be the same as the start time and the end time must not
be the same with the end time';
$chk = false;
}
else{
echo 'ELSE no other choice insert here';
$chk = true;
}
}
if($chk == true){
echo "insert there";
mysql_query("INSERT INTO time(date,stime,etime)values('$date','$stime','$etime')");
}else{
echo "break the statement";
}
}
} else{
echo 'do not insert';
}
}
?>
<form method="post">
start<input type="time" name="stime">
end<input type="time" name="etime"><br>
<input type="submit" name="reserve" value="reserve">
</form>
</body>
</html>