我希望代码在其中roommate为null的Student_room表中插入一行。例如,当我尝试在roomate_id
的地方插入room_id= Block 1/R2
时,应该在The room is fully occupied....
的地方插入roomate_id
并打印room_id = Block 1/R1
。
else {
$sql2 = $mysqli->query("SELECT * FROM `student_room` WHERE room_id = '$room_id' AND roomate_id IS NULL AND academic_year = '$academic_year'");
if($sql2->num_rows == 0) {
echo "<p2>The double room is fully occupied please check other rooms</p2>";
} else {
$assign = "UPDATE `student_room` SET roomate_id = $student_id WHERE room_id = '$room_id'";
if (mysqli_query($mysqli, $assign)) {
$update = "UPDATE `room` SET room_status = 'occupied' WHERE room_id = '$room_id'";
}
if (mysqli_query($mysqli, $update)) {
$app_no = $mysqli->query("SELECT app_id FROM `application` WHERE student_id = $student_id");
$row = mysqli_fetch_array($app_no);
$app_id = $row['app_id'];
$username = $_SESSION['username'];
$sql3 ="INSERT INTO `staff_application` (username, app_no, academic_year) VALUES ('$username', $app_id, '$academic_year')";
}
if (mysqli_query($mysqli, $sql3)) {
echo "<p2>Room successfully assigned</p2>";