//connected to db
if (isset($_POST['teacherusername'])) {
$_SESSION['teacherusername'] = $_POST['teacherusername'];
}
$sql = "SELECT TeacherId FROM Teacher WHERE (TeacherUsername = ?)";
$stmt=$mysqli->prepare($sql);
$stmt->bind_param("s",$_SESSION['teacherusername']);
$stmt->execute();
$record = $stmt->fetch();
$teacherid = $record['TeacherId'];
$stmt->close();
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
$time = str_replace(array(' Hrs ', ' Mins ', ' Secs'), array(':', ':', ''), $_SESSION['durationChosen']);
$insertsql = "INSERT INTO Session (SessionId, SessionTime, SessionDate, SessionWeight, SessionDuration, TotalMarks, ModuleId, TeacherId, Room) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
$insert = $mysqli->prepare($insertsql);
for ($i = 1, $n = $_SESSION['sessionNum']; $i <= $n; ++$i) {
$sessid = $_SESSION['id'] . ($n == 1 ? '' : $i);
$sessdate = date("Y-m-d", strtotime($_SESSION['dateChosen']));
$insert->bind_param("sssssssss", $sessid, $_SESSION['timeChosen'], $sessdate,
$_SESSION['textWeight'], $time, $_SESSION['textMarks'],
$_SESSION['module'], $teacherid, $_SESSION['rooms']);
$insert->execute();
if ($insert->errno) { echo "Error in insert: $insert->error<br>\r\n"; }
$insert->close();
}
}
更新:
以前的错误已得到修复,但我现在收到 4 个警告,如下所示:
警告:mysqli_stmt::bind_param() [mysqli-stmt.bind-param]:无法在第 177 行的 /web/stud/.../Mobile_app/insertsession.php 中获取 mysqli_stmt
警告:mysqli_stmt::execute() [mysqli-stmt.execute]:无法在第 179 行的 /web/stud/.../Mobile_app/insertsession.php 中获取 mysqli_stmt
警告:main() [function.main]:无法在第 181 行的 /web/stud/.../Mobile_app/insertsession.php 中获取 mysqli_stmt
警告:mysqli_stmt::close() [mysqli-stmt.close]:无法在第 185 行的 /web/stud/.../Mobile_app/insertsession.php 中获取 mysqli_stmt
由于 mysqli 现在正在向数据库中插入数据,我应该处理这些警告还是不理会它们?
问题已解决,未来的观众请看 DAVE RANDOM 的回答