My SQL PDO INSERT query does not appear to be inserting data into the table and does not return any error message stating why it can’t do this. Any idea as to what is going on?
UPDATE: I’m getting the following error message array(3) { [0]=> string(5) "00000" [1]=> NULL [2]=> NULL } after running var_dump($pdo->errorInfo())
$dept = $_POST['dept'];
$module_id = $_POST['moduleCode'];
$day_id = $_POST['day'];
$period_id = $_POST['period'];
$length_id = $_POST['length'];
$semester = $_POST['semester'];
$round = $_POST['round'];
$group_size = $_POST['group_size'];
$room_structure = $_POST['room_structure'];
$lecture_style = $_POST['lecture_style'];
$roomAllocation = $_POST['roomAllocation'];
$notes = $_POST['notes'];
// insert request into table
$sql = "INSERT INTO ts_request
(dept_id,
module_id,
day_id,
period_id,
length_id,
semester,
round,
group_size,
room_structure,
lecture_style,
park_id,
allocation
notes)
VALUES
(:dept,
:module_id,
:day_id,
:period_id,
:length_id,
:semester,
:round,
:group_size,
:room_structure,
:lecture_style,
:park,
:allocation
:notes)";
$stm = $pdo->prepare( $sql );
$stm->execute( array( ':dept' => $dept,
':module_id' => $module_id,
':day_id' => $day_id,
':period_id' => $period_id,
':length_id' => $length_id,
':semester' => $semester,
':round' => $round,
':group_size' => $group_size,
':room_structure' => $room_structure,
':lecture_style' => $lecture_style,
':park' => $park,
':allocation' => $roomAllocation,
':notes' => $notes ) );
$request_id = $pdo->lastInsertId();
// create allocation
$sql = "INSERT INTO ts_allocation
(request_id,
status)
VALUES
(:request_id,
:status";
$stm = $pdo->prepare( $sql );
$stm->execute( array( ':request_id' => $request_id,
':status' => $status ) );
$allocation_id = $pdo->lastInsertId();
// insert weeks
$weeks = explode(",", $_POST["weeks"]);
for ($i = 0; $i < count($weeks); $i++) {
$sql = "INSERT INTO ts_week
(request_id,
allocation_id,
week)
VALUES
(:request_id,
:allocation_id,
:week)";
$stm = $pdo->prepare( $sql );
$stm->execute( array( ':request_id' => $request_id,
':allocation_id' => $allocation_id,
':week' => $weeks[$i] ) );
}
// insert fac pref
$roomFac = explode(",", $_POST["roomFac"]);
for ($i = 0; $i < count($roomFac); $i++) {
$sql = "INSERT INTO ts_facpref
(request_id,
facilities_id)
VALUES
(:request_id,
:facilities_id)";
$stm = $pdo->prepare( $sql );
$stm->execute( array( ':request_id' => $request_id,
':facilities_id' => $roomFac[$i] ) );
}
// insert room pref
$room_id = explode(",", $_POST["roomPref"]);
for ($i = 0; $i < count($room_id); $i++) {
$sql = "INSERT INTO ts_roompref
(request_id,
room_id)
VALUES
(:request_id,
:room_id)";
$stm = $pdo->prepare( $sql );
$stm->execute( array( ':request_id' => $request_id,
':room_id' => $room_id[$i] ) );
}
var_dump($stm->errorInfo());
Use
var_dump($pdo->errorInfo())AND$stm->errorInfo();after every statement to see what errors PDO gives.P.s. you have errors in your queries. You miss last bracket:
and this