我得到:命令不同步;你现在不能 运行 这个命令?
I get: Commands out of sync; you can't run this command now?
我想执行两个查询,但收到“命令不同步;您现在不能 运行 此命令”
我已经查看了同一问题的先前问题,但无法找出解决方案。我知道这是因为我 运行宁两个查询。
谁能告诉我我做错了什么?
查询一:
if($_SERVER["REQUEST_METHOD"] == "POST"){
$sql = "INSERT INTO offer (uniqid, status, l_comp)
VALUES ('test1', 'AFVENTER TILBUD', 'test1');";
$sql .= "INSERT INTO offer (uniqid, status, l_comp)
VALUES ('test2', 'AFVENTER TILBUD', 'test2');";
$sql .= "INSERT INTO offer (uniqid, status, l_comp)
VALUES ('test3', 'AFVENTER TILBUD', 'test3')";
if ($link->multi_query($sql) === TRUE) {
查询二:
$sql = "SELECT * FROM offer_requests WHERE username = '" .
($_SESSION["username"]) . "'";
if($result = mysqli_query($link,
$sql)){
if(mysqli_num_rows($result) > 0){
echo "<th></th>";
echo "<th></th>";
echo "<th></th>";
echo "</tr>";
while($row =
mysqli_fetch_array($result)){
echo "<tr>";
echo "<th
class='hidden'>" . $row['uniqid'] . "</th>";
echo "<th>" .
$row['car'] . "</th>";
echo "<th>" .
$row['l_comp_one'] . "</th>";
echo "<th>" .
$row['l_comp_two'] . "</th>";
echo "<th>" .
$row['l_comp_three'] . "</th>";
echo "<th>";
echo "<a
href='read_request.php?uniqid=". $row['uniqid'] ."' title='Se
tilbudsanmodning' data-toggle='tooltip'><span class='glyphicon
glyphicon-eye-open'></span></a>";
echo "</th>";
echo "</tr>";
}
// Free result set
mysqli_free_result($result);
} else{
echo "</br></br><p><b><i>Ingen
informationer fundet.</i></b></p>";
}
} else{
echo "ERROR: Was not able to
execute $sql. " . mysqli_error($link);
}
echo "</tbody>";
echo "</table>";
如果我正确理解了另一个答案,这就是该怎么做:
if ($link->multi_query($sql) === TRUE) {
// the loop below is the fix. It just cycles through the results, ignoring them
while(mysqli_more_results($link)) {
mysqli_next_result($link);
// or $link->next_result();
}
//...
我想执行两个查询,但收到“命令不同步;您现在不能 运行 此命令” 我已经查看了同一问题的先前问题,但无法找出解决方案。我知道这是因为我 运行宁两个查询。
谁能告诉我我做错了什么?
查询一:
if($_SERVER["REQUEST_METHOD"] == "POST"){
$sql = "INSERT INTO offer (uniqid, status, l_comp)
VALUES ('test1', 'AFVENTER TILBUD', 'test1');";
$sql .= "INSERT INTO offer (uniqid, status, l_comp)
VALUES ('test2', 'AFVENTER TILBUD', 'test2');";
$sql .= "INSERT INTO offer (uniqid, status, l_comp)
VALUES ('test3', 'AFVENTER TILBUD', 'test3')";
if ($link->multi_query($sql) === TRUE) {
查询二:
$sql = "SELECT * FROM offer_requests WHERE username = '" .
($_SESSION["username"]) . "'";
if($result = mysqli_query($link,
$sql)){
if(mysqli_num_rows($result) > 0){
echo "<th></th>";
echo "<th></th>";
echo "<th></th>";
echo "</tr>";
while($row =
mysqli_fetch_array($result)){
echo "<tr>";
echo "<th
class='hidden'>" . $row['uniqid'] . "</th>";
echo "<th>" .
$row['car'] . "</th>";
echo "<th>" .
$row['l_comp_one'] . "</th>";
echo "<th>" .
$row['l_comp_two'] . "</th>";
echo "<th>" .
$row['l_comp_three'] . "</th>";
echo "<th>";
echo "<a
href='read_request.php?uniqid=". $row['uniqid'] ."' title='Se
tilbudsanmodning' data-toggle='tooltip'><span class='glyphicon
glyphicon-eye-open'></span></a>";
echo "</th>";
echo "</tr>";
}
// Free result set
mysqli_free_result($result);
} else{
echo "</br></br><p><b><i>Ingen
informationer fundet.</i></b></p>";
}
} else{
echo "ERROR: Was not able to
execute $sql. " . mysqli_error($link);
}
echo "</tbody>";
echo "</table>";
如果我正确理解了另一个答案,这就是该怎么做:
if ($link->multi_query($sql) === TRUE) {
// the loop below is the fix. It just cycles through the results, ignoring them
while(mysqli_more_results($link)) {
mysqli_next_result($link);
// or $link->next_result();
}
//...