在mysqli/php代码中添加2个SELECT查询会导致错误

在mysqli/php代码中添加2个SELECT查询会导致错误,php,mysqli,Php,Mysqli,我在下面有一个php/mysqli代码,它可以成功地插入问题和答案: $i = 0; $c = count($_POST['numQuestion']); $questionsql = "INSERT INTO Question (SessionId, QuestionId, QuestionContent) VALUES (?, ?, ?)"; $sessid = $_SESSION['id'] . ($_SESSION['i

我在下面有一个php/mysqli代码,它可以成功地插入问题和答案:

$i = 0;
$c = count($_POST['numQuestion']);

$questionsql = "INSERT INTO Question (SessionId, QuestionId, QuestionContent) 
                    VALUES (?, ?, ?)";



        $sessid =  $_SESSION['id'] . ($_SESSION['initial_count'] > 1 ? $_SESSION['sessionCount'] : '');

            if (!$insert = $mysqli->prepare($questionsql)) {
      // Handle errors with prepare operation here
    } else{

for($i = 0;  $i < $c; $i++ ){      


$results = $_POST['value'];
foreach($results as $id => $value) {
$answer = $value;


        $insert->bind_param("sis", $sessid, $id, $_POST['questionText'][$i]);

        $insert->execute();

        if ($insert->errno) {
          // Handle query error here
        }

       $lastID = $insert->insert_id;

       $insert->close();

        foreach($value as $answer) {

         $answersql = "INSERT INTO Answer (SessionId, QuestionId, Answer) 
    VALUES (?, ?, ?)";

      if (!$insertanswer = $mysqli->prepare($answersql)) {
      // Handle errors with prepare operation here
    }  

    $insertanswer->bind_param("sis", $sessid, $lastID, $answer);

        $insertanswer->execute();

        if ($insertanswer->errno) {
          // Handle query error here
        }

        $insertanswer->close();

}
}

}

}

这里发生了两个不同的问题。首先,
命令不同步
警告正在发生,因为您试图在实际完成以前的查询之前启动新的查询。有关详细信息,请参阅。基本上,在准备下一个查询之前,您必须关闭正在准备的每个查询

至于
无法中断/继续
错误,发生这种情况的原因是,当您只有1层深度时,您正在调用
中断2
中断
(或
继续
)后的可选数字是要中断的“级别”数

<?php
for($i = 0; $i < 10; $i++){
    // 1 level
    for($j = 0; $j < 10; $j++){
        // 2 levels

        break;      // Break of the $j loop
        break 1;    // Equivalent to above

        break 2;    // Break out of both the $j and $i loops

        break 3;    // Causes an error - there is no third level
    }
}

<?php
for($i = 0; $i < 10; $i++){
    // 1 level
    for($j = 0; $j < 10; $j++){
        // 2 levels

        break;      // Break of the $j loop
        break 1;    // Equivalent to above

        break 2;    // Break out of both the $j and $i loops

        break 3;    // Causes an error - there is no third level
    }
}