我有一个不起作用的多重查询。当我在前一页按下提交时,我进入一个空白页面,表中没有插入任何内容" answer_det"在我的数据库和文本"信息存储成功"没有出现。我做错了什么?
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
if(mysqli_connect_errno())
{
echo mysqli_connect_error();
}
$pid5 = $_POST['pid4'];
$aid1 = $_POST['a1'];
$aid2 = $_POST['a2'];
$aid3 = $_POST['a3'];
$aid4 = $_POST['a4'];
$answ1 = $_POST['ans1'];
$answ2 = $_POST['ans2'];
$answ3 = $_POST['ans3'];
$answ4 = $_POST['ans4'];
$point1 = $_POST['pointset1'];
$point2 = $_POST['pointset2'];
$point3 = $_POST['pointset3'];
$point4 = $_POST['pointset4'];
$que = "INSERT INTO answer_det VALUES('$pid5','','$aid1','$answ1','$point1')";
$que .= "INSERT INTO answer_det VALUES('$pid5','','$aid2','$answ2','$point2')";
$que .= "INSERT INTO answer_det VALUES('$pid5','','$aid3','$answ3','$point3')";
$que .= "INSERT INTO answer_det VALUES('$pid5','','$aid4','$answ4','$point4')";
$run = mysqli_multi_query($mysqli,$que);
if($run)
{
echo "<br>Information stored successfully";
}
else
{
echo mysql_error();
}
?>
&#13;
答案 0 :(得分:2)
如果您只需要插入这些数据,则无需多次查询,使用此命令将代码作为一个查询运行:
$que = "INSERT INTO answer_det VALUES('$pid5','','$aid1','$answ1','$point1'), ";
$que .= "('$pid5','','$aid2','$answ2','$point2'), ";
$que .= "('$pid5','','$aid3','$answ3','$point3'), ";
$que .= "('$pid5','','$aid4','$answ4','$point4');";
$run = mysqli_query($mysqli, $que);
答案 1 :(得分:1)
除了我的评论(添加分号):
$que = "INSERT INTO answer_det VALUES('$pid5','','$aid1','$answ1','$point1');";
$que .= "INSERT INTO answer_det VALUES('$pid5','','$aid2','$answ2','$point2');";
$que .= "INSERT INTO answer_det VALUES('$pid5','','$aid3','$answ3','$point3');";
$que .= "INSERT INTO answer_det VALUES('$pid5','','$aid4','$answ4','$point4');";
$run = mysqli_multi_query($mysqli,$que);
请参阅清楚显示的PHP manual:
执行一个或多个由a连接的查询 分号。