I was making a hotel database, and wrote a query which should print out all available rooms in a certain period, but when I run it, it does not print out anything. It uses information from the tables booking and rooms. Here is the php code, along with the html code. Can someone please tell me what I am doing wrong here?
<HTML>
<head> </head>
<body>
<h3>Choose the period to see which are the free rooms:</h3>
<form action="query2.php" method ="GET"><br>
<fieldset>
<div class="field">
<div class="pick-date">
<label for="date_from"></label>
From: <input type="date" name="a">
<br/><br/>
<div class="field">
<label for="date_to">
To: <input type="date" name="b">
</label>
</div> <br/>
<div class="field">
<label for="room_type">
Room type:
<select name="room type[]">
<option></option>
<option>Classic single</option>
<option>Superior single</option>
<option>Classic double</option>
<option>Superior double</option>
<option>Vip room</option>
<option>Family room</option>
</select>
<br/><br/>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
<?php
$x = isset($_GET['room type[]']);
if (!isset($_GET['a']))
{$a = null; }
elseif (!is_string($_GET['a'])) {
$a = false;
} else { $a = $_GET['a'];
}
$b = isset($_GET['b']) && is_string($_GET['b']) ? $_GET['b'] :'';
$query=mysql_query(
"select r_id, r_type, r_price
from Rooms
WHERE r_type='$x' and r_id not in
(select b_rooms
from booking
where (b_checkin >= '$a' and b_checkin < '$b')
or (b_checkout >= '$a' and b_checkout < '$b'));" );
if (!$query) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
while ($row = mysql_fetch_assoc($query))
{
echo $row['r_type'];
echo" ";
echo $row['r_price'];
echo" ";
echo $row['r_id'];
echo"<br>";}
mysql_free_result($query);
?>