Advertisement
girlyou

How to display room type in room type column(php table)?

Oct 18th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.13 KB | None | 0 0
  1. <?php
  2.   $servername = "localhost";
  3.   $username = "root";
  4.   $password = "";
  5.   $database = "safarihostel";
  6.   $conn = mysqli_connect($servername, $username, $password, $database);
  7.  
  8. if (isset($_POST['addroom'])) {
  9.     $rt = $_POST['rtype'];
  10.     $rn = $_POST['rno'];
  11.     $rr = $_POST['rrate'];
  12.     $mp = $_POST['maxp'];
  13.  
  14.     mysqli_query($conn, "INSERT INTO `rooms`(`room_type`, `room_rate`, `room_no`, `max_person`) VALUES ('$rt','$rr','$rn','$mp')");
  15. }
  16. ?>
  17.  
  18. <!DOCTYPE html>
  19. <html>
  20. <body>
  21.     <table class="table table-bordered table-striped mb-none" id="datatable">
  22.         <thead>
  23.           <tr>  
  24.               <th>Room Type</th>
  25.               <th>Room Rate</th>
  26.               <th>Room No.</th>
  27.               <th>Max Person</th>
  28.           </tr>  
  29.         </thead>  
  30.         <tbody>  
  31.     <?php
  32. $sql = "SELECT * FROM rooms";
  33.   if ($result = mysqli_query($conn, $sql)) {
  34.     if (mysqli_num_rows($result) > 0) {
  35.     while ($row = mysqli_fetch_array($result)) {?>
  36.     <tr>
  37.           <td><?php echo $row['room_type']; ?></td>
  38.           <td><?php echo $row['room_rate']; ?></td>
  39.           <td><?php echo $row['room_no']; ?></td>
  40.           <td><?php echo $row['max_person']; ?></td>
  41.  
  42.         </tr>
  43.      <?php }
  44.    }
  45.  }
  46.  ?>
  47.         </tbody>  
  48.     </table>
  49.  
  50.                 <div class="modal fade" id="add">
  51.   <div class="modal-dialog">
  52.     <div class="modal-content">
  53.  
  54.       <form method="POST" action="" role="form" id="addroom">
  55.  
  56.       <div class="modal-header">
  57.         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  58.         <h4 class="modal-title">Add Room</h4>
  59.       </div>
  60.  
  61.       <div class="modal-body" style="color: black;">
  62.         <p><label> Room Type: </label>
  63.               <select class="input-sm" name="rtype" id="rtype" onchange="rooms()" required>
  64.                 <option></option>
  65.                 <?php
  66.                   $roomtype = "SELECT * FROM roomtypes";
  67.                   $roomresult = mysqli_query($conn, $roomtype);
  68.                   while ($row = mysqli_fetch_array($roomresult)) {?>
  69.                     <option value="<?php echo $row[2]; ?>"><?php echo $row[1];?> </option>
  70.                  <?php }
  71.                 ?>
  72.               </select></p>
  73.  
  74.          <p><label> Room Rate: </label>
  75.               <input type="text" class="input-sm" name="rrate" id="rrate" required></p>
  76.  
  77.         <p><label> Room No.: </label>
  78.                 <input type="text" class="input-sm" name="rno" id="rno" required></p>
  79.  
  80.         <p><label>Max Person: </label>
  81.                   <input type="text" class="input-sm" name="maxp" value="" onkeypress="return isNumberKey(event)" required></p>
  82.  
  83.       </div>
  84.  
  85.       <div class="modal-footer">
  86.         <button type="submit" class="btn btn-primary" name="addroom">SAVE</button>
  87.       </div>
  88.      
  89.     </form>
  90.     <div class="clearfix"></div>
  91.     </div><!-- /.modal-content -->
  92.   </div><!-- /.modal-dialog -->
  93. </div><!-- /.modal -->
  94.  
  95. <script>
  96.   (function() {
  97.     document.getElementById('rtype').onclick = function () {
  98.         rrate.value = rtype.value;    
  99.         }    
  100.     }());
  101. </script>
  102. </body>
  103. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement