为什么我只在数据库中插入一行,它会显示成功消息,但是如果我在数据库中插入多行,那么它不会显示成功消息?
下面是代码:
$studentid = (isset($_POST['addtextarea'])) ? $_POST['addtextarea'] : array();
$sessionid = (isset($_POST['Idcurrent'])) ? $_POST['Idcurrent'] : array();
$insertsql = "
INSERT INTO Student_Session
(SessionId, StudentId)
VALUES
(?, ?)
";
if (!$insert = $mysqli->prepare($insertsql)) {
// Handle errors with prepare operation here
}
foreach($studentid as $id)
{
$insert->bind_param("ii", $sessionid, $id);
$insert->execute();
if ($insert->errno) {
echo json_encode(array('errorflag'=>true,'msg'=>"An error has occured, Students have not been added into the Assessment"));
}else{
echo json_encode(array('errorflag'=>false,'msg'=>"Students have been successfully added into the Assessment"));
}
}
$insert->close();
?>