Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $database = "safarihostel";
- $conn = mysqli_connect($servername, $username, $password, $database);
- if (isset($_POST['addroom'])) {
- $rt = $_POST['rtype'];
- $rn = $_POST['rno'];
- $rr = $_POST['rrate'];
- $mp = $_POST['maxp'];
- mysqli_query($conn, "INSERT INTO `rooms`(`room_type`, `room_rate`, `room_no`, `max_person`) VALUES ('$rt','$rr','$rn','$mp')");
- }
- ?>
- <!DOCTYPE html>
- <html>
- <body>
- <table class="table table-bordered table-striped mb-none" id="datatable">
- <thead>
- <tr>
- <th>Room Type</th>
- <th>Room Rate</th>
- <th>Room No.</th>
- <th>Max Person</th>
- </tr>
- </thead>
- <tbody>
- <?php
- $sql = "SELECT * FROM rooms";
- if ($result = mysqli_query($conn, $sql)) {
- if (mysqli_num_rows($result) > 0) {
- while ($row = mysqli_fetch_array($result)) {?>
- <tr>
- <td><?php echo $row['room_type']; ?></td>
- <td><?php echo $row['room_rate']; ?></td>
- <td><?php echo $row['room_no']; ?></td>
- <td><?php echo $row['max_person']; ?></td>
- </tr>
- <?php }
- }
- }
- ?>
- </tbody>
- </table>
- <div class="modal fade" id="add">
- <div class="modal-dialog">
- <div class="modal-content">
- <form method="POST" action="" role="form" id="addroom">
- <div class="modal-header">
- <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
- <h4 class="modal-title">Add Room</h4>
- </div>
- <div class="modal-body" style="color: black;">
- <p><label> Room Type: </label>
- <select class="input-sm" name="rtype" id="rtype" onchange="rooms()" required>
- <option></option>
- <?php
- $roomtype = "SELECT * FROM roomtypes";
- $roomresult = mysqli_query($conn, $roomtype);
- while ($row = mysqli_fetch_array($roomresult)) {?>
- <option value="<?php echo $row[2]; ?>"><?php echo $row[1];?> </option>
- <?php }
- ?>
- </select></p>
- <p><label> Room Rate: </label>
- <input type="text" class="input-sm" name="rrate" id="rrate" required></p>
- <p><label> Room No.: </label>
- <input type="text" class="input-sm" name="rno" id="rno" required></p>
- <p><label>Max Person: </label>
- <input type="text" class="input-sm" name="maxp" value="" onkeypress="return isNumberKey(event)" required></p>
- </div>
- <div class="modal-footer">
- <button type="submit" class="btn btn-primary" name="addroom">SAVE</button>
- </div>
- </form>
- <div class="clearfix"></div>
- </div><!-- /.modal-content -->
- </div><!-- /.modal-dialog -->
- </div><!-- /.modal -->
- <script>
- (function() {
- document.getElementById('rtype').onclick = function () {
- rrate.value = rtype.value;
- }
- }());
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement