<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