Problems querying database
Posted: Thu Apr 15, 2004 8:17 am
MOD EDIT: PLEASE CAN YOU USE THE BBCODE TO HIGHLIGHT YOUR PHP....THANKS 
Hi
I am currently developing a booking system. I will be renting holiday homes. On one menu i have a drop down menu where the user select the housename that he/she wishes to stay in and they also enter a start date and an end date. to ensure that there is no double booking ,the system must first check that this house is available for the period of time. I have managed to get the date fields checking against the fields in the database but i am unable to get the house one working Heres an example:
I have two houses, one called houseA and HouseB. HouseA has been booked for the week 2004-02-01 - 2004-02-07. Now if a new user comes along and tries to book this house for that week the system should say "soory house booked". And it does. The problem is that it does the same for houseB as well. The housnames for the drop down menu are obtained by a connection to the house table.
Does anyone have any idea what could be wrong? I have checked that i ma calling te text boxes and drop down boxes the correct name ie $startdate, $enddate and $housename. Basically i think that the problem lies with the first query. The other queries work fine.
Any help would be greatly appreciated.
Thx
Gerry
Hi
I am currently developing a booking system. I will be renting holiday homes. On one menu i have a drop down menu where the user select the housename that he/she wishes to stay in and they also enter a start date and an end date. to ensure that there is no double booking ,the system must first check that this house is available for the period of time. I have managed to get the date fields checking against the fields in the database but i am unable to get the house one working Heres an example:
I have two houses, one called houseA and HouseB. HouseA has been booked for the week 2004-02-01 - 2004-02-07. Now if a new user comes along and tries to book this house for that week the system should say "soory house booked". And it does. The problem is that it does the same for houseB as well. The housnames for the drop down menu are obtained by a connection to the house table.
Code: Select all
?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($enddate < $startdate)
{
echo "booking out date must be later than the book in date!";
}
if($startdate < $enddate)
{
$query0 = "select * from custorder
where '".$housename."' = Housename";
$mysql_result0 = mysql_query($query0);
$num0 = @mysql_num_rows($mysql_result0);
if ($num0 > 0)
{
$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 = false;
echo "sorry this date is not available1";
}
$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 = false;
echo "sorry this date is not available2";
}
$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 = false;
echo "sorry this date is not available3";
}
}
else {
echo "dates available";
}
?>Any help would be greatly appreciated.
Thx
Gerry