I am currently running a simple php/mysql booking system which allows users to book blocks of time (see attached image).
I want to add the option for users to book:
All Morning,
All Afternoon,
All Evening, or All Day.
So, it should not allow users to book anything if “All Day” is already booked, or shouldnt allow users to book period 1, period 2, break or perido 3 if “all morning” is already booked.
Here is the code i am currently running, which allows users to book individual blocks and stops other users from booking a resource which is already booked at that time on that day.
[code=php]<h1>Make Booking</h1>
<?
//initilize PHP
if($_POST[‘submit’]) //If submit is hit
{
if ($resource==”Select Resource” ) {
die(‘You did not select a resource, please check and <A HREF=”javascript:history.go(-1)”>Try again</A>’);
}
if ($period==”Select Period” ) {
die(‘You did not select a period, please check and <A HREF=”javascript:history.go(-1)”>Try again</A>’);
}
if ($date==”” ) {
die(‘You did not select a date, please check and <A HREF=”javascript:history.go(-1)”>Try again</A>’);
}
if ($name==”” ) {
die(‘You did not enter your name, please check and <A HREF=”javascript:history.go(-1)”>Try again</A>’);
}
if ($comments==”” ) {
die(‘You did not enter a reason for this booking, please check and <A HREF=”javascript:history.go(-1)”>Try again</A>’);
}
//Insert the values into the correct database with the right fields
//mysql table = news
//table columns = id, title, message, who, date, time
//post variables = $title, $message, ‘$who, $date, $time
$fields = “id, resource, period, date, name, comments”;
$result = “INSERT INTO $tblname ($fields) VALUES (‘NULL’, ‘$resource’, ‘$period’, ‘$date’, ‘$name’, ‘$comments’)”;
// * Check for duplicates.
$request = “SELECT * FROM $tblname”;
$db_result = mysql_query($request);
$article = mysql_fetch_object($db_result);
$num_rows = mysql_num_rows($db_result);
$row_count = 0;
while ($row_count < $num_rows) { // While I haven’t checked all the rows.
$article = mysql_fetch_object($db_result); // Put each object into $article.
$row_count++; // * And add one to row count.
if ($article->resource == $resource) { // If session equates to session…
if ($article->period == $period) {
if ($article->date == $date) {
echo “The booking you specified is already taken. <a href=’javascript:history.go(-1)’>Try again</a>”;
exit();
}
}
}
}
$add_record = mysql_query($result);
$str10 = substr($nstory, 0, 50);
//confirm
echo “<h2>Booking Complete</h2> <br /><strong>Resource:</strong> $resource
<br /><strong>Period:</strong> $period
<br /><strong>Date:</strong> $date
<br /><strong>Name:</strong> $name
<br /><strong>Comments:</strong> $comments
<br />
<br /><a href=’makebooking.php’><strong>Click here to make another Booking…</strong></a>”;
}
else
{
// close php so we can put in our code
?>
Any help would be greatly appreciated.
[upl-file uuid=502ce68d-f829-4282-b5ab-c27a8d0e7345 size=49kB]booking.gif