php - Failing prepared statement. Not getting string -
i getting following error line of code...
warning: mysqli::query() expects parameter 1 string, object given
for
if ($result2 = $con->query($stmt2)) {
and cannot figure out? connections correct, prepared statement above it. have tried moving stuff on page , read because mixing mysqli , mqsql, how doing sql?
what causing 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 * forum_topics `category_id`=? , `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 add reply</p><hr /></td></tr>"; } } while ($row = $stmt->fetch()) { //prepared select stmt forum posts if($stmt2 = $con->prepare("select `id`, `category_id`, `topic_id`, `post_creator`, `post_content`, `post_date` forum_posts `category_id`=? , `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 /> ".$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 not exist.</p>"; } } catch (exception $e) { echo "error: " . $e->getmessage(); }
it because trying execute query string using prepared statement object: in code $stmt2 prepared statement object $stmt2 = $con->prepare("selec
Comments
Post a Comment