命令不同步,无法计算出正确的代码顺序

时间:2019-05-20 19:15:48

标签: php mysql select command-objects

我从我的代码中收到以下错误消息:“未捕获的mysqli_sql_exception:命令不同步;您现在不能运行此命令”。 我从这个网站上的类似问题知道这意味着什么 我尝试做的事情很简单,但是除了我做过的之外,我不知道该怎么做。我已经读过使用PDO的可能性,但是我还没有真正掌握PDO,还有其他方法可以实现吗?

我有一个页面,允许用户从数据库中删除记录,因此有一个delete命令和select命令可以检索数据库中的记录。即使我收到显示的错误消息,删除命令仍在运行。

这不是我页面上的所有代码,而是适用于此问题的所有代码:

<?php
$deletepost = 'none';
$deleteposterror = 'none';
$show_div = 'none';
$hide_div = 'show';
?>
<?php

    if(isset($_POST['topic_id_value'])) {

    $del_topic_id = $_POST['topic_id_value'];

    // sql to delete a record
    $pass_fail = "DELETE FROM topics WHERE topic_id ='$del_topic_id';";

    $pass_fail .= "DELETE FROM posts WHERE topic_id_post ='$del_topic_id'";

    if (mysqli_multi_query($conn, $pass_fail)) {

    $deletepost = 'show';

    }else{

    $deleteposterror = 'show';
    echo "ERROR: Could not able to execute $pass_fail. "  . mysqli_error($conn);    

    }

}

?>

<?php
        $sql1 = "SELECT * FROM topics WHERE topic_by = '".$id."' AND has_comment = '0'";
        $result=$conn->query($sql1);

       if ($result->num_rows === 0) {

            $show_div = 'show';
            $hide_div = 'none';

        }else if ($result->num_rows > 0) {



    ?>



            <?php
                while($row = $result->fetch_assoc()) {

            $topic_id = $row ['topic_id'];
            $topic_subject = $row ['topic_subject']; 
            $my_date = $row['topic_date'];
            $date = DATE("G:i:s d/m/Y",strtotime($my_date));
                ?>  

            <div class='chat_post_titles' >
            <div class='row'>
            <div class='col-md-7 chat_post_text_align_left'>
            <a href="../Chat/post.php?topic_id=<?php echo $topic_id?>"><?php echo $topic_subject?>.</a>
            </div>
            <div class='col-md-2 chat_post_text_align_right'>
            <div class='hide_text'>Post Date: </div>
            <?php echo $date?>
            </div>
            <div class='col-md-2 chat_post_text_align_centre'>
            <div class='hide_text'>Delete Post: </div>

            <form method="post" onSubmit="return submit();" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
            <input type="hidden" name="topic_id_value" id="topic_id_value" value="<?php echo $topic_id?>">
            <button type="submit" class="btn btn-danger buttonElement">Delete</button>
            </form>
            </div>
            </div>
            </div>
            <?php
                    }


        }
                ?>

0 个答案:

没有答案