doujiang1001 2015-07-23 12:55
浏览 17

准备不充分的声明。 没有得到字符串

I am getting the following error for this line of code...

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

for

        if ($result2 = $con->query($stmt2)) {

and I cannot figure it out? My connections are correct, as is the prepared statement above it. I have tried moving stuff all over the page and read that it could be because I am mixing mysqli and mqsql, but how is what I am doing my sql?

What would be causing this error?

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();
}
  • 写回答

2条回答 默认 最新

  • doudao3170 2015-07-23 13:06
    关注

    It is because you are trying to execute a query string using a Prepared Statement OBJECT: in your code $stmt2 is a prepared statement object $stmt2 = $con->prepare("SELEC

    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程