Multiple request not executed

I have some queries that do not work. When I click the submit button on the previous page, I get to a blank page and nothing is inserted into the table "answer_det" in my database, and the text "Information saved successfully" does not appear. What am I doing wrong?

<?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();
}


?>
Run codeHide result
+4
source share
2 answers

In addition to my comment (added semicolons):

$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);

Refer to the PHP manual where it clearly reads:

Performs one or more queries that are joined by a semicolon.

+1
source

, . :

$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);
+2

Source: https://habr.com/ru/post/1622078/


All Articles