I have a table that has a list of clients on a waiting list where you can select to move one of them into a vacant room.
When you select this client, it moves onto a page called 'MoveIn1.html' where it gets that client's ID and uses it to display his/her name and ID. It also displays a drop-down box showing all the rooms that are vacant, giving the user a choice of which room to move the client into. The user then also chooses the date the client will move in and submits this information.
After it is submitted, it goes onto 'MoveIn2.php' where it should update the client's active to '1' (aka, yes), update the selected room's room_vacant to '0' (aka, no) and create/insert into a new occupancy record, along with the client's id (occupancy_client_id), the room id (occupancy_room_id) and the start date. I don't get a single error but my tables do not get updated and no occupancy record is created; when echo'ing my carried variables nothing is displayed either so I'm not sure how to sort this. Any help will be much appreciated.
Some of MoveIn1.html code:
$id = $_GET['id'];
//SELECTS from client where the selected client's ID is equal to client_id
$stmt = $dbh->prepare("SELECT * FROM client WHERE client_id=:id");
$stmt->bindParam(':id', $id);
$stmt->execute();
$row = $stmt->fetch();
echo "<b>Client ID: </b>" . $row['client_id'];
echo "<br><br>";
echo "<b>Client Name: </b>" . $row['first_name'] . " " . $row['last_name'];
echo "<br><br>";
///////////////////////////////////////////////////////////////
//Creates a form for room_id
echo "<form action='MoveIn2.php'>";
//Creates drop down box to show the current rooms vacant
echo "<b>Choose a room: </b>";
$sql = "SELECT * FROM room";
$sql.= " WHERE room_vacant = 1";
$stmt = $dbh->query($sql);
echo "<select name='room_id'>";
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo "<option value='" . $row['room_id'] . "'>" . $row['room_id'] . "</option>";
} //Closes drop down box
echo "</select><br><br>";
//Move-in date
echo "<b>Move-in date: </b>";
echo "<input type='date' name='start_date' value='" . date("Y/m/d") . "' required/><br><br>";
echo "<input type='hidden' name='id' value='" . $id . "'/>";
echo "<input type='hidden' name='submit' value='submit' />";
//Submit button
echo "<input type='submit' value='Submit'><br><br>";
echo "<input type='button' name='cancel' value='Cancel' onclick='window.location='ViewWaitingList.html'' /><br><br>";
//Closes form
echo "</form>";
/////////////////////////////////////////////////////////////////
?>
Some of MoveIn2.php code:
<?php
require("dbconnect.php");
//CLIENT
$id = $_POST['id'];
//UPDATES client's to 1/Yes to say that they're now an active client in JRH,
//where the selected client's ID is equal to :id
$stmt = $dbh->prepare("UPDATE client SET active = 1 WHERE client_id=:id");
$stmt->bindParam(':id', $id);
$stmt->execute();
//ROOM
$room_id = $_POST['room_id'];
$stmt = $dbh->prepare("UPDATE room SET room_vacant = 0 WHERE room_id = :room_id");
$stmt->bindParam(':room_id', $room_id);
$stmt->execute();
//OCCUPANCY
$id = $_POST['id'];
$room_id = $_POST['room_id'];
$start_date = $_POST['start_date'];
$stmt = $dbh->prepare("INSERT INTO occupancy (occupancy_client_id, occupancy_room_id, start_date) VALUES(:id, :room_id, :start_date)");
$stmt->bindParam(':id', $id);
$stmt->bindParam(':room_id', $room_id);
$stmt->bindParam(':start_date', $start_date);
$stmt->execute();
echo $id;
echo $room_id;
echo $start_date;
?>
MoveIn1.htmlto run as PHP? If not, you'll need to rename it toMoveIn1.php, otherwise that code won't run.