Booking System Problem
Posted: Tue Apr 20, 2004 9:24 am
the system i am developing is an online holiday homes booking system. I have several houses which can be booked. If users wish to book a house then they are brought to a check dates page where they enter the house they wish to rent. The list of houses is in a displayed in a list box where the values are obtained from the house table. When the user wishes to book a house they simply select a house and enter a start date and an end date and click submit. The problem is that the system does not seem to be distinguishing one house from another. It seems to be lloking at all the vaules present in the list box and not just the one the prvious user had booked. Heres an example: Say i have two house housA and HouseB. HouseA has benn booked for a week in june. Another person wants to book houseB for the same week but the system wont allow him to do so cause it thinks there is a booking. I have included the code for the web page and the actual checking scrip. The web page also has PHP script to enable it to obtain the houses from the house table..
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<form method="post" action="date.php">
<p> </p>
<p> </p>
<p> </p>
<p>
Below is the actual checking script..
would someone be able to tell me is it definatly taking in a value from the list box??
Any help would be appreciated
Thx
Gerry
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<form method="post" action="date.php">
<p> </p>
<p> </p>
<p> </p>
<p>
Code: Select all
<?php
<?php
$connection=mysql_connect("localhost","","");
# use the following connection if you are logging in with no username # / password
# $connection=mysql_connect("localhost","","");
if (!$connection) {
echo "Could not connect to MySQL server!";
exit;
}
$db=mysql_select_db("travel_system",$connection);
if (!$db) {
echo "Could not change into the database";
exit;
}
$sql="SELECT housename FROM house";
$mysql_result=mysql_query($sql,$connection);
$num_rows=mysql_num_rows($mysql_result);
if ( $num_rows == 0 ) {
echo "Sorry there is no information";
} else {
echo "Please select a house <BR>";
echo "<SELECT NAME="housename">";
while ($row=mysql_fetch_array($mysql_result))
{
$f_house=$row["housename"];
# display results
echo "<OPTION>$f_house";
}
echo "</SELECT>";
} # end else
?> </p>
<table width="70%" border="0" cellpadding="2">
<tr>
<td width="50%">
<div align="right">Enter Start Date </div>
</td>
<td width="50%">
<input type="text" name="startdate">
</td>
</tr>
<tr>
<td width="50%" height="51">
<div align="right">Enter End Date </div>
</td>
<td width="50%" height="51">
<input type="text" name="enddate">
</td>
</tr>
<tr>
<td width="50%" height="2"> </td>
<td width="50%" height="2">
<input type="submit" name="Submit" value="Check Dates">
</td>
</tr>
</table>
<p> </p>
</form>
</body>
</html>
?>Below is the actual checking script..
Code: Select all
<?php
<?php
$connection=mysql_connect("localhost","root","");
if (!$connection)
{
echo "Could not connect to MySQL server!";
exit;
}
$db=mysql_select_db("travel_system",$connection);
if (!$db)
{
echo "Could not change into the database";
exit;
}
if(empty($startdate))
{
echo "please enter a startdate";
}
if(empty($enddate))
{
echo "please enter an end date";
}
if($enddate < $startdate)
{
echo "booking out date must be later than the book in date!";
}
if($startdate < $enddate)
{
$valid == false;
$query0 = "select * from custorder
where '$housename' = Housename ";
$mysql_result0 = mysql_query($query0);
$num0 = @mysql_num_rows($mysql_result0);
if($num0 == 0)
{
echo "dates available";
}
if ($num0 > 0 )
{
// query to check if the new start and end date are in the middle of an existing booking
$query = "select * from custorder
where '".$startdate."' >= startdate AND '".$startdate."' <= enddate";
$mysql_result = mysql_query($query);
$num = @mysql_num_rows($mysql_result);
if ($num > 0 )
{
$valid == true;
} // end if
// query to check if the either the new startdate or end date is in the middle of an existing booking
$query2 = "select * from custorder
where '".$enddate."' >= startdate AND '".$enddate."' <= enddate";
$mysql_result2 = mysql_query($query2);
$num = @mysql_num_rows($mysql_result2);
if ($num > 0 )
{
$valid = true;
} // end if
// query to check if the new startdate and enddate begin before and end after an existing booking
$query3 = "select * from custorder
where '".$startdate."' <= startdate AND '".$enddate."' >= enddate";
$mysql_result3 = mysql_query($query3);
$num = @mysql_num_rows($mysql_result3);
if ($num > 0 )
{
$valid = true;
} // end if
}
if($valid)
{
echo "sorry dates not available";
}
}
?>
?>Any help would be appreciated
Thx
Gerry