$strSQL = "SELECT * FROM booking WHERE r_id = '".$room."'
AND
(
(sdate between '".$sdate."' AND '".$edate."') OR (edate between '".$sdate."' AND '".$edate."') or
('".$sdate."' between sdate AND edate) OR ('".$edate."' between sdate AND edate)
)
AND
(
('".$stime."' between stime AND etime) OR ('".$etime."' between stime AND etime )
OR (stime between '".$stime."' and '".$etime."') OR (etime between '".$stime."' and '".$etime."')
)
$mtime = 00+10;
$sdate=$_POST['date1'];
$edate=$_POST['date2'];
$stime1 = $_POST['hour1'].':'.$_POST["min1"].':'.$mtime;
$etime1 = $_POST['hour2'].':'.$_POST["min2"].':'.$mtime;
$stime = $_POST['hour1'].':'.$_POST["min1"].':'.'00';
$etime = $_POST['hour2'].':'.$_POST["min2"].':'.'00';
$room=$_POST['txtroom'];
$m_id=$_POST['txtm_id'];
$sex=$_POST['txtsex'];
$org=$_POST['txtorg'];
$tel=$_POST['txttel'];
$fax=$_POST['txtfax'];
$mail=$_POST['txtmail'];
$detail=$_POST['txtdetail'];
echo $stime;
echo $etime;
$strSQL = "SELECT * FROM booking WHERE r_id = '".$room."'
AND
(
(sdate between '".$sdate."' AND '".$edate."') OR (edate between '".$sdate."' AND '".$edate."') or
('".$sdate."' between sdate AND edate) OR ('".$edate."' between sdate AND edate)
)
AND
(
('".$stime1."' BETWEEN stime AND etime) OR ('".$etime1."' BETWEEN stime AND etime )
OR (stime between '".$stime1."' and '".$etime1."') OR (etime between '".$stime1."' and '".$etime1."')
)
";
$objQuery = mysql_query($strSQL) or die(mysql_error());
$objResult = mysql_fetch_array($objQuery);
if($objResult)
{
echo "<script>alert('ห้องนี้มีผู้ใช้งานแล้วกรุณาตรวจสอบอีกครั้ง!');history.back();</script>";
}
elseif($stime > $etime){
echo "<script>alert('เวลาเริ่มต้นน้อยกว่าเวลาสิ้นสุด!');history.back();</script>";
}
else
{
$sql_insert = " INSERT INTO `booking` (`m_id` ,`appdate` ,`sdate` ,`edate` ,`stime` ,`etime` ,`r_id` ,`detail` ,`status` )";
$sql_insert.= " VALUES('".$m_id."','".date("Y-m-d")."','".$sdate."','".$edate."', '".$stime."', '".$etime."','".$room."','".$detail."','0'); ";
$objQuery = mysql_query($sql_insert) or die(mysql_error());