Php 未准备好的声明。没有得到字符串

Php 未准备好的声明。没有得到字符串,php,mysql,while-loop,prepared-statement,Php,Mysql,While Loop,Prepared Statement,我得到这行代码的以下错误 Warning: mysqli::query() expects parameter 1 to be string, object given 为了 我想不出来?我的联系是正确的,上面的陈述也是正确的。我试着在整个页面上移动内容,读到可能是因为我混合了mysqli和mqsql,但是我的sql是怎么做的呢 是什么导致了这个错误 try { $cid = $_GET['cid']; $tid = $_GET['tid']; $userid = ( isset( $_SES

我得到这行代码的以下错误

Warning: mysqli::query() expects parameter 1 to be string, object given
为了

我想不出来?我的联系是正确的,上面的陈述也是正确的。我试着在整个页面上移动内容,读到可能是因为我混合了mysqli和mqsql,但是我的sql是怎么做的呢

是什么导致了这个错误

try {
$cid = $_GET['cid'];
$tid = $_GET['tid'];
$userid = ( isset( $_SESSION['user'] ) ? $_SESSION['user'] : "" );
    echo $cid . "<br>";
    echo $tid;
//Prepare
if ($stmt = $con->prepare("SELECT * FROM forum_topics WHERE `category_id`=? AND `id`=? LIMIT 1")) {

    $stmt->bind_param("ii", $cid, $tid);
    $stmt->execute();
    $stmt->bind_result($topic_id, $category_id, $topic_title, $topic_creator, $topic_last_user, $topic_date, $topic_reply_date, $topic_views); 

    //var_dump($stmt);

    if (!$stmt) {
        throw new Exception($con->error);
    }
}
$stmt->store_result();
$numrows = $stmt->num_rows;
echo $numrows;


if($numrows == 1){
    echo "<table width='100%'>";
    if ( $_SESSION['user'] ) { 
        echo "<tr><td colspan='2'><input type='submit' value='Add Reply' onclick=\"window.location = 
    'forum_post_reply.php?cid=".$cid."$tid=".$tid."'\"> <hr />";
    } else {
        echo "<tr><td colspan='2'><p>Please log in to add your reply</p><hr /></td></tr>";
    }
    }

    while ($row = $stmt->fetch()) {

        //Prepared SELECT stmt to get forum posts
        if($stmt2 = $con->prepare("SELECT `id`, `category_id`, `topic_id`, `post_creator`, `post_content`, `post_date` FROM forum_posts WHERE `category_id`=? AND `topic_id`=?")) {

        //var_dump($stmt2);

            $stmt2->bind_param("ii", $cid, $tid);
            $stmt2->execute();
            $stmt2->store_result();
            $stmt2->bind_result($post_id, $post_category_id, $post_topic_id, $post_creator, $post_content, $post_date);
            if (!$stmt2) {
            throw new Exception($con->error);
            }
        }
    }
    if ($result2 = $con->query($stmt2)) {
        while ($row2 = $result2->fetch_assoc() ) {
            echo "<tr><td valign='top' style='border: 1px solid #000000;'>
            <div style='min-height: 125px;'>".$row['topic_title']."<br />
            by ".$row2['post_creator']." - " .$row2['post_date']. "<hr />" . $row2['post_content'] ."</div></td>
            <td width='200' valign='top' align='center' style='border: 1px solid #000000;'>User Info Here!</td></tr>
            <tr><td colspan='2'><hr /></td></tr>";
        }   
    }   else {
        echo "<p>This topic does not exist.</p>";
        }
}
catch (Exception $e)
{
    echo "Error: " . $e->getMessage();
}
试试看{
$cid=$_GET['cid'];
$tid=$_GET['tid'];
$userid=(isset($\u会话['user'])?$\u会话['user']:“”);
echo$cid。“
”; echo$tid; //预备 如果($stmt=$con->prepare(“从论坛主题中选择*,其中'category\u id`=?和'id`=?LIMIT 1')){ $stmt->bind_参数(“ii”、$cid、$tid); $stmt->execute(); $stmt->bind_result($topic_id、$category_id、$topic_title、$topic_creator、$topic_last_user、$topic_date、$topic_reply_date、$topic_views); //var_dump($stmt); 如果(!$stmt){ 抛出新异常($con->error); } } $stmt->store_result(); $numrows=$stmt->num_行; echo$numrows; 如果($numrows==1){ 回声“; 如果($_会话['user']){ 回声“
”; }否则{ echo“请登录添加您的回复”


”; } } 而($row=$stmt->fetch()){ //准备选择stmt以获取论坛帖子 如果($stmt2=$con->prepare(“从论坛帖子中选择`id`、`category\u id`、`topic\u id`、`post\u creator`、`post\u content`、`post\u date`,其中`category\u id`=?和`topic\u id`=?”){ //var_dump($stmt2); $stmt2->bind_参数(“ii”、$cid、$tid); $stmt2->execute(); $stmt2->store_result(); $stmt2->bind_result($post_id、$post_category_id、$post_topic_id、$post_creator、$post_content、$post_date); 如果(!$stmt2){ 抛出新异常($con->error); } } } 如果($result2=$con->query($stmt2)){ 而($row2=$result2->fetch_assoc()){ 回声“ “$row['topic_title']。”
通过“$row2['post_creator']”引用-“$row2['post_date']”,
“$row2['post_content']” 用户信息在这里!
; } }否则{ echo“此主题不存在。

”; } } 捕获(例外$e) { 回显“错误:”..e->getMessage(); }
这是因为您正试图使用准备好的语句对象执行查询字符串:在代码中,$stmt2是一个准备好的语句对象$stmt2=$con->prepare(“SELEC

这是因为您试图使用准备好的语句对象执行查询字符串:在代码中$stmt2是一个准备好的语句对象$stmt2=$con->prepare(“SELEC

如果
条件未用于
分配
它用于
compere
的变量,请更改您的条件。”

$stmt2 = $con->prepare("SELECT `id`, `category_id`, `topic_id`, `post_creator`, `post_content`, `post_date` FROM forum_posts WHERE `category_id`=? AND `topic_id`=?");
        if($stmt2===false) {

         // DO some error message
         }else{
          // Rest code
        }

$stmt2=$con->prepare()
在这里,您可以编写
您的查询
而不是prepare语句
$con->query('your query')
如果
条件未用于
分配
它用于
compere
的变量,请使用

$stmt2 = $con->prepare("SELECT `id`, `category_id`, `topic_id`, `post_creator`, `post_content`, `post_date` FROM forum_posts WHERE `category_id`=? AND `topic_id`=?");
        if($stmt2===false) {

         // DO some error message
         }else{
          // Rest code
        }

$stmt2=$con->prepare()
在这里您编写
您的查询
,而不是prepare语句
$con->query('your query'))

我在第一次查询中做了同样的事情,没有得到任何错误?我如何着手修复它?我如何解决它?我仍然不完全理解你的意思。我在第一次查询中做了同样的事情,没有得到任何错误?我如何着手修复它?我如何解决它?我仍然不完全理解你的意思你的意思是。你的意思是把if语句从那一行去掉?然后
$stmt2=$con->prepare()
在这里你写你的查询而不是prepare语句
$con->query('Your query')
我得到这个错误。
解析错误:语法错误,意外的'if'(T\u if)
使用
if($stmt2==false)
我错误地添加了一个额外的括号。我仍然会在这一行中得到错误…
if($result2=$con->query($stmt2))
警告:mysqli::query()希望参数1是字符串,对象给定我
你的话,将if语句从那一行中去掉?并且
$stmt2=$con->prepare()
在这里,您编写了您的查询,而不是prepare语句
$con->query('your query')
我得到了这个错误。
解析错误:语法错误,意外的'if'(T\u if)
使用
if($stmt2==false)
我错误地添加了一个额外的括号。我仍然得到这一行的错误…
if($result2=$con->query($stmt2))
警告:mysqli::query()要求参数1是字符串,给定的对象i
$stmt2
必须是不带
的真实查询字符串?
$stmt2
必须是不带
的真实查询字符串?