$strSQL = "SELECT * FROM booking WHERE ((sdate between '".$sdate."' and '".$edate."') or ";
$strSQL .= " (edate between '".$sdate."' and '".$edate."')) and ";
$strSQL .= " room = '".$_POST["txtroom"]."' and time = '".$time."' ";
$objQuery = mysql_query($strSQL)or die(mysql_error());
$objResult = mysql_fetch_array($objQuery);
if($objResult)
{
echo "<script>alert('ห้องนี้มีผู้ใช้งานแล้วกรุณาตรวจสอบอีกครั้ง!');history.back();</script>";
}