我的 SQL PDO INSERT 查询似乎没有将数据插入表中,并且没有返回任何错误消息说明它为什么不能这样做。关于发生了什么的任何想法?
更新:array(3) { [0]=> string(5) "00000" [1]=> NULL [2]=> NULL }
运行后我收到以下错误消息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());