Jump to content

Preventing the double time booking in Reservation


fsaylo

Recommended Posts

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

 

 

"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 
"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. :(

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.