Hi to all,
i am preparing an appointment booking web site for my uni project. However i am stuck on the last booking.php file. It enters the appointment start time and endtime however it shows Start Time: 11:00:00
Finish Time: 11:30:00
Duration: 0:30:00
Have been taken please select other times
and it inserts the information to the database however it does not overwrite it. Very interesting:))) Please take a look at the code and tell me what should i do cos i am not expert in php> Thanks
<?php
session_start();
include ("db.php");
$sectionname="Welcome To Berna's Unisex Hair Salon";
$pagename="Choose Staff";
echo "<html>";
echo "<head>";
echo "<title>".$sectionname.">>>".$pagename."</title>";
echo "<link rel=stylesheet type=text/css href=pageform.css>";
echo "</head>";
echo "<body>";
echo "<center><i><h1 style=calibre;color:black>Berna's Unisex Hair Salon Page</h1><i/>";
echo "<center><b><i><p style=calibre;color:black>Since 1994</p></i></b>";
echo date ('l d F Y H:i:s');
echo "<hr><img src=header.jpg><hr>";
echo "</center>";
echo "<br>";
echo "<br>";
$sesstaff = $_SESSION['staff'];//staffid
$sesclient = $_SESSION['userid'];//client id
$_SESSION['date'];//date
$sestime = $_SESSION['time'];//time
$TotalNoservice = count($_SESSION['sel1']);/counting number selected duration id
//serviceId serviceName serviceDuration
$alltime = 0;
for($i=0; $i<$TotalNoservice; $i++)
{
$ServiceName = $_SESSION['sel1'][$i];
$query="select duration from services where service_id = $ServiceName";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
$alltime = $alltime + $row['duration'];
}
}
$th = substr($sestime, 0, 2);
$tm = substr($sestime, 3, 2);
$ts = substr($sestime, 6, 2);
$th = $th + floor($alltime/3600);
$th2 = floor($alltime/3600);
$alltime = $alltime - floor($alltime/3600)*3600;
$tm = $tm + floor($alltime/60);
$tm2 = floor($alltime/60);
$alltime = $alltime - floor($alltime/60)*60;
$ts = $ts + $alltime;
$ts2 = $alltime;
if ($ts < 10) $ts = "0".$ts;
if ($ts2 < 10) $ts2 = "0".$ts2;
$result = mysql_query("SELECT * FROM booking WHERE staff_id='$sesstaff'");
$found = 0;
while($row = mysql_fetch_array($result))
{
$csh = substr($row['booking_start'], 0, 2);
$cfh = substr($row['booking_end'], 0, 2);
if(substr($sestime, 0, 2) >= $csh && substr($sestime, 0, 2) <= $cfh)
{
$found = 1;
}
if(substr($th, 0, 2) >= $csh && substr($sestime, 0, 2) <= $cfh)
{
$found = 1;
}
}
echo "Start Time: ".$sestime."<br>";
echo "Finish Time: ".$th.":".$tm.":".$ts."<br>";
echo "Duration: ".$th2.":".$tm2.":".$ts2."<br>";
if($found == 1){
echo "Have been taken please select other times";
}
elseif($found == 0)
{
echo "Your times have been booked thanks for booking with COMPANY NAME";
$finishtime = $th.":".$tm.":".$ts;
mysql_query("INSERT INTO booking (client_id, staff_id, booking_start, booking_end)VALUES ('$sesclient', '$sesstaff', '$sestime', '$finishtime')");
}
echo "</body>";
echo "</html>";
?>
Help needed in appointment booking:(
Moderator: General Moderators
- mecha_godzilla
- Forum Contributor
- Posts: 375
- Joined: Wed Apr 14, 2010 4:45 pm
- Location: UK
Re: Help needed in appointment booking:(
I'm not quite sure what you want to achieve so more details would be helpful 
If the time slot is available then a record is added (inserted) into the database, but if the time slot is not available then you just get an error message. Is that right? If the time slot is not available but the booking still gets added then there's something wrong with your script logic (IE $found still equals 0 when it should equal 1). Echo-ing out the values at different points in the script will tell you what's going on.
One thing I didn't understand was your comment about the record being inserted but not overwritten - if you want the record overwritten you have to use an UPDATE query; the format looks something like this:
HTH,
Mecha Godzilla
If the time slot is available then a record is added (inserted) into the database, but if the time slot is not available then you just get an error message. Is that right? If the time slot is not available but the booking still gets added then there's something wrong with your script logic (IE $found still equals 0 when it should equal 1). Echo-ing out the values at different points in the script will tell you what's going on.
One thing I didn't understand was your comment about the record being inserted but not overwritten - if you want the record overwritten you have to use an UPDATE query; the format looks something like this:
Code: Select all
UPDATE bookings
SET booking_start = '$booking_start', booking_end = '$booking_end'
WHERE booking_id = '$booking_id'Mecha Godzilla