1

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:&nbsp;&nbsp;&nbsp;&nbsp;<input type="date" name="a"> 
        <br/><br/>                    
        <div class="field">
        <label for="date_to">
        To:&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<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"&nbsp; &nbsp;";
            echo $row['r_price'];
        echo"&nbsp; &nbsp;";
            echo $row['r_id'];
        echo"<br>";}
        mysql_free_result($query);
        ?>
Milan
  • 631
  • 1
  • 5
  • 21
Felicity
  • 63
  • 1
  • 1
  • 8
  • `mysql_*` functions are deprecated since PHP 5.5 (and removed entirely in PHP 7) and you shoud [stop using them](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) if you can. You should choose another API, like `mysqli_*` or PDO instead - see [choosing an API](http://php.net/manual/en/mysqlinfo.api.choosing.php). – Qirel Jan 09 '16 at 13:04
  • Also, `x = isset($_GET['room type[]']);` is an expression, not a variable. – Qirel Jan 09 '16 at 13:07
  • Thank you, I`ll try this. I hope this helps me – Felicity Jan 09 '16 at 13:21
  • Look into Take a look at [`error_reporting(E_ALL);`](http://php.net/manual/en/function.error-reporting.php) and [`ini_set('display_errors', 1);`](http://php.net/manual/en/function.ini-set.php) – Qirel Jan 09 '16 at 13:21

0 Answers0