fsaylo Posted April 30, 2013 Share Posted April 30, 2013 Hi. I am having problem based on my reservation system, I want to prevent it from double time booking. If the one data is choosing 12pm to 1p, and if I register again the same time it'll still be registered in the database. Please can you help me with this problem. Here is my code, the one that is uploaded and the same with posted here. res.php <?php if(isset($_POST['submit'])) { if ($type && $start_time && $end_time) { $connect = mysql_connect("localhost","root","") or die ("Couldn't connect!"); mysql_select_db("globalhub") or die ("Couldn't find db"); // db ang name sa database $query = mysql_query("SELECT COUNT * FROM reservation WHERE type='$type' AND start_time>=('$start_time') AND end_time<=('$end_time') "); $row1=mysql_fetch_array($query); if(($row1!=0) { if ($type && $start_time && $end_time) { echo "<script type='text/javascript'>\n"; echo "alert('Please choose another time.');\n"; echo "</script>"; $_SESSION['type']=$type; } else { $connect=mysql_connect("localhost","root",""); mysql_select_db("globalhub"); error_reporting (E_ALL ^ E_NOTICE); $sql = "INSERT INTO reservation (fullname, contact, email, position, company, type, start_date, end_date, start_time, end_time, purpose) VALUES ('$_POST[fullname]','$_POST[contact]','$_POST','$_POST[position]','$_POST[company]','$_POST[type]','$_POST[start_date]','$_POST[end_date]','$_POST[start_time]','$_POST[end_time]','$_POST[purpose]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } } } } } mysql_close($con); ?> Quote Link to comment Share on other sites More sharing options...
requinix Posted April 30, 2013 Share Posted April 30, 2013 "SELECT COUNT * FROM reservation WHERE type='$type' AND start_time>=('$start_time') AND end_timeI believe last time I had to think about this the answer was "SELECT COUNT * FROM reservation WHERE type='$type' AND end_time>('$start_time') AND start_timeThat will not consider two reservations as overlapping if they start or stop on the same boundary (ie, one ends at the same time another begins). Use >= and Quote Link to comment Share on other sites More sharing options...
fsaylo Posted April 30, 2013 Author Share Posted April 30, 2013 "SELECT COUNT * FROM reservation WHERE type='$type' AND start_time>=('$start_time') AND end_time<=('$end_time') "I believe last time I had to think about this the answer was "SELECT COUNT * FROM reservation WHERE type='$type' AND end_time>('$start_time') AND start_time<('$end_time')"That will not consider two reservations as overlapping if they start or stop on the same boundary (ie, one ends at the same time another begins). Use >= and <= respectively if you want them to. Hi, I already changed you preferred code but it seems that it still save the same time and end time of the reservation. Quote Link to comment Share on other sites More sharing options...
Barand Posted April 30, 2013 Share Posted April 30, 2013 if(($row1!=0) should be if(($row1[0] != 0) Quote Link to comment Share on other sites More sharing options...
requinix Posted April 30, 2013 Share Posted April 30, 2013 There's also an extra ( there that would break the entire script. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.