我有一个表单,我想用一个进程创建多达9个不同的MySQL行。我现在的代码不会抛出任何错误,但也不会将任何信息插入数据库。
$id = '';
$rid = $_POST['rid'];
$desc = $_POST['desc'];
$ename = $_POST['ename'];
if ($stmt = $mysqli->prepare("INSERT INTO event(id, rid, desc, ename) VALUES (?, ?, ?, ?)")) {
$stmt->bind_param("isss", $id, $rid, $desc, $ename);
for ($i = 1; $i < 10; $i++) {
$rid = $_POST['rid' . $i];
$desc = $_POST['desc' . $i];
$ename = $_POST['ename' . $i];
$stmt->execute();
}
include ("./html/schedule2.htm");
} else {
printf("Errormessage: %s\n", $mysqli->error);
}
我已编辑代码以遵循评论说明,但仍然会收到非常模糊的错误。不知道发生了什么......
答案 0 :(得分:0)
评论指出你应该准备/执行这个。这应该是它的样子。
$id = '';
$rid = $_POST['rid1'];
$desc = $_POST['desc1'];
$ename = $_POST['ename1'];
$stmt = $mysqli->prepare("INSERT INTO `event`(`id`, `rid`, `desc`, `ename`) VALUES (?, ?, ?, ?)");
$stmt->bind_param("ssss", $id, $rid, $desc, $ename);
$stmt->execute();
for ($i = 2; $i < 10; $i++) {
$rid = $_POST['rid' . $i];
$desc = $_POST['desc' . $i];
$ename = $_POST['ename' . $i];
$stmt->execute();
}
另外,我建议为表单元素使用数组。像:
<input type="text" name="desc[]">