$response = ""; $resId = preg_replace('#[^0-9]#', '', $_POST['confirm']); $sqlSel = "SELECT rs.*, rm.available " . "FROM RESERVATION AS rs " . "LEFT JOIN ROOM AS rm " . "ON rs.room_theme = rm.room_theme" . "WHERE rs.res_id = '{$resId}'"; $result = mysqli_query($conn, $sqlSel) or die(mysli_error($conn)); $check_result = mysqli_num_rows($result); if ($check_result != 0) { while ($row = mysqli_fetch_array($result)) { //delete the reserved seat $del_room_theme = $row['room_theme']; $del_reserved = $row['reserved_seats']; //update the room table $id = $row['room_id']; $room_theme = $row['room_theme']; $orig_avail = $row['available']; //add back the canceled booking $update_avail = $orig_avail + $del_reserved; //delete the booked room from the reservation table $sqlDel = "DELETE FROM RESERVATION WHERE room_theme='{$del_room_theme}'"; $resultDel = mysqli_query($conn, $sqlDel) or die(mysli_error($conn)); //update the room table to its original state $sqlUpd = "UPDATE ROOM SET available = '{$update_avail}' WHERE room_theme='{$del_room_theme}'"; $resultUpd = mysqli_query($conn, $sqlUpd) or die(mysli_error($conn)); } } else { $spots = "Full"; $reserveId = "open"; } echo $spots | $reservId; exit; } //**********END Confirm Booking
<?php include 'database/connect.php'; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ $id = 300; $num = 2; $sqlSel = "SELECT * FROM ROOM WHERE room_id ='" . $id . "' AND capacity >= '" . $num . "'"; $result = mysqli_query($conn, $sqlSel) or die(mysli_error($conn)); $check_result = mysqli_num_rows($result); if ($check_result != 0) { while ($row = mysqli_fetch_array($result)) { $id = $row['room_id']; $room_theme = $row['room_theme']; $status = $row['status']; $cap = $row['capacity']; $price = $row['price']; } } $stat = "NOT AVAILABLE"; $sqlUpd = "UPDATE ROOM SET status = '" . $stat . "' WHERE room_id='" . $id . "'"; mysqli_query($conn, $sqlUpd) or die(mysli_error($conn)); $sqlIns = "INSERT INTO RESERVATION(room_theme, reserved_seats) VALUES('" . $room_theme . "', '" . $num . "')"; mysqli_query($conn, $sqlIns) or die(mysli_error($conn)); //mysqli_insert_id($connect);