hi i realise that this code is a mess at the moment
i cant even get it to work in the browser at the moment
it gives me the error:
Parse error: parse error, unexpected T_ELSE in C:\APACHE2\Apache2\htdocs\add_book.php on line 91
which is the else in the lines which is before the form starts:
else {
$accommid = $_POST['accommID'];
i have confused myself completly with all the if's and elseif's and the brackets that go with each.
however i am trying to do a booking script that will search to see if the dates that the users have entered are avaialable for a particular accommodation.
also i need to be able to solve the concurrent user problem to ensure that an accommodation cant be double booked.
can any1 tell me if i am even along the right lines with wot i am trying to do with the following code because i have spent alot of time on it and now im not sure if i am approaching it in complelty the wrong way!
<?php
session_start();
if(!isset($_SESSION['user_name'])) { echo "<p><center>Please login to view this page.</p><p> </p> Please wait... You will automatically be redirected back to the login page";
echo "<META HTTP-EQUIV=Refresh CONTENT='3; URL=gen_homepage.php'>";
} else {
?>
<html>
<head>
<title>Add Booking</title>
<link rel="stylesheet" type="text/css" href="template2.css">
<head>
<body>
<table border="1" width="100%" height="226">
<tr>
<td width="22%" height="91" bgcolor="#0099FF">
<img alt ="[Company Logo]"
src="puj2.gif" width="100" height="100">
<p>
</td>
<td width="78%" height="91" bgcolor="#66CCFF" ALIGN=CENTER>
<H1> Add Booking </H1>
</td>
</tr>
<tr>
<td width="22%" height="123" bgcolor="#6699FF">
<div class="buttonscontainer">
<div class="buttons">
<a href="cust_homepage.php">Customer Homepage</a>
<a href="calendar.php">Calendar</a>
<a href="logout.php">Logout</a>
</div>
</div>
</td>
<td width="78%" height="123" bgcolor="#99CCFF" ALIGN=CENTER>
<p> </p>
<?
if(isset($_POST['submit'])){
require_once("config.php");
$connection = @mysql_connect($db_host, $db_user, $db_password) or die("oops! error connecting");
mysql_select_db($db_name, $connection);
$accommID = $_POST ["accommID"];
$book_start = $_POST ["booking_start_date"];
$book_end = $_POST ["booking_end_date"];
$query = "INSERT INTO booking (booking_start_date, booking_end_date, accommID) VALUES ('$book_start','$book_end','$accommID')";
$result = mysql_query($query) or die (mysql_error());
if(!$result){
echo "Booking not added
</td>
</table>";
} //closes if not result
//elseif {
$date1 = $book_start; //booking start date
$date2 = $book_end; //booking end date
$timestamp1 = strtotime($date1);
$timestamp2 = strtotime($date2);
if($timestamp1 > $timestamp2){
echo "Please enter a Booking Start Date that is before the Booking End Date";
}
//find if the dates they have entered are available for the accommID selected. If the $booking start and $booking_end is less then then those already stored in teh field names mentioned
//then the flag will be 0 saying that the accomm is available
if ($query2 = "select $accommID from booking group by $accommID
having sum(case when ((booking_start_date < $book_start && booking_end_date < $book_end) || (booking_start_date > $book_start && booking_end_date > $book_end)
then 0 else 1 end) = 0"){
$result2 = mysql_query ($query2) or die(mysql_error());
echo "The dates are available";
//if the dates are available then join the type from accommodation with booking by matching the accommID in both tables
//then check the dates again and if the flag is still 0 then allow booking else dates are not available.
($query3 ="select type from accommodation left join booking on accommID = accommID group by $accommID
having sum (case when ((booking_start_date < $book_start and booking_end_date < $book_end) or (booking_start_date > $book_start and booking_end_date > $book_start)
then 0 else 1 end) = 0") or die(mysql_error());
//$result3 = mysql_query ($query3) or die(mysql_error());
}//closes elseif
elseif (!$result2){
echo "The dates are not available";
}
echo "</td>
</table>";
else {
$accommid = $_POST['accommID'];
?>
<form action ="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type=hidden name=accommID value="<?=$accommid?>">
<p align="center"> </p>
<p align="center"><u>Booking Start Date (YYYY/MM/DD):</u> <input type="text" name="booking_start_date" size="20"></p>
<p align="center"><u>Booking End Date (YYYY/MM/DD) :</u> <input type="text" name="booking_end_date" size="20"></p>
<p> </p>
<p><input type="submit" name=submit value="Submit"></p>
</form>
</td>
</table>
<?
} //closes else above
echo "</body>
</html>";
} //close if submit
}//closes sessions if
?>
hope someone can help because i just seem to be more and more confused with it
thanks