0

i am developing a registration system that queries the database for a list of available rooms if the registered members of that room are less than 5 the room is seen as available. i want a dropdown to be populated by the list of available rooms on button click without refreshing the page.

this is the html:

         <div class="too-many">
           <div class="center-too-many">
             <div class="label-room">
               <div class="labas"><label for="hostel">Hostel: </label></div>
               <div class="labas"><label for="r_type">Room Type: </label></div>
             </div>
             <div class="labels-input room">
               <!--Hostel-->
               <?php
               if ($row['gender'] == 'Male') {
                 $option1 = 'Banabas';
                 $option2 = 'Banabas Annex';
               }
               else {
                 $option1 = 'Faith';
                 $option2 = 'Faith Annex';
               }?>
               <div class="labas"><div class="form-group">
                 <div class="input-group input-group-sm">
                   <select class="form-control" name="hostel" required>
                     <option></option>
                     <option><?php echo $option1; ?></option>
                     <option><?php echo $option2; ?></option>
                   </select>
                 </div>
               </div></div>
               <!--Hostel-->

               <!--Room Type-->
               <div class="labas"><div class="form-group">
                 <div class="input-group input-group-sm">
                   <select class="form-control" name="r_type" required>
                     <option></option>
                     <option>Executive</option>
                     <option>Standard</option>
                   </select>
                 </div>
               </div></div>
               <!--Room Type-->


             </div>

             <input type="submit" name="check" value="CHECK AVALIBILITY" class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored" id="magic" />

             <div class="label-room">
               <div class="labas"><label for="av_rooms">Avalible rooms: </label></div>
             </div>
             <div class="labels-input room">
               <!--Room Class-->
               <div class="labas"><div class="form-group">
                 <div class="input-group input-group-sm">
                   <select class="form-control" name="av_rooms">
                     <?php echo $msg; ?>
                   </select>
                 </div>
               </div></div>
               <!--Room Class-->
             </div>

             <input type="submit" name="register" value="REGISTER" class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored" id="magic" />

           </div>
           </div>
     </form> 

and the php:

   <?php
  if (isset($_POST['check'])) {
    $hostel = $_POST['hostel'];
    $type = $_POST['r_type'];
    if ($type == 'Standard') {
      $_POST['r_type'] = 'SR';
    }
    else {
      $_POST['r_type'] = 'ER';
    }
    if ($hostel == 'Banabas' && $type == 'SR') {
      $query = 'SELECT room_no, COUNT(room_no) as count FROM banabas_sr GROUP BY room_no HAVING count BETWEEN 0 AND 6';
      $ex = mysql_query($query);
      while ($row = mysql_fetch_array($ex)) {
        echo $msg = "<option value='" . $row['room_no'] . "'>" . $row['room_no'] . "</option>";
      }
    }
  }
 ?>

when i click check it is supposed to populate the dropdown and register would write the data to the database. the dropdown isn't populating. i don't know if it's the sql query, the syntax i used or the fact that the page still refreshes and i dont't know how to make it stop. a little insight would be very helpful.

adinell
  • 69
  • 7

0 Answers0