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

 

 

Link to comment
Share on other sites

"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 
Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.