php - Prepared statement is failing -


i trying create forum. in prepared statement, trying get forum_topic , forum_posts. furthermore in code trying see posts made individual topic, if looking @ topic on here , see posts(comments).

i getting correct values $tid , $cid. believe issue has prepare part of this, not sure. else statement...

echo "<p>this topic not exist.</p>"; 

but actual topic , should have post it.

does see doing wrong?

my full code:

error_reporting(e_all); ini_set('display_errors', 1);  try { $con = new mysqli("localhost", "", "", ""); if (mysqli_connect_errno()) {     throw new exception("connect failed: %s\n", mysqli_connect_error());     exit(); } $cid = $_get['cid']; $tid = $_get['tid']; $userid = ( isset( $_session['user'] ) ? $_session['user'] : "" );  //prepare if ($stmt = $con->prepare("select * forum_topics `category_id`=? , `id`=? limit 1")) {      $stmt->bind_param("ii", $cid, $tid);     $stmt->execute();     $stmt->fetch();       if (!$stmt) {         throw new exception($con->error);     } } $stmt->store_result(); $numrows = $stmt->num_rows; 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>";     }  foreach($stmt $row) {      //prepared select stmt forum posts     if($stmt2 = $con->prepare("select * forum_posts `category_id`=? , `topic_id`=?")) {     //var_dump($stmt2);          $stmt2->bind_param("ii", $cid, $tid);         $stmt2->execute();     }            while (mysqli_stmt_fetch($stmt)) {             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(); } 

i thought might show database tables trying pull from.

forum_topics create table `forum_topics` (  `id` int(11) not null auto_increment,  `category_id` int(11) not null,  `topic_title` varchar(150) collate utf8_unicode_ci not null,  `topic_creator` int(11) not null,  `topic_last_user` int(11) default null,  `topic_date` datetime not null,  `topic_reply_date` datetime not null,  `topic_views` varchar(255) collate utf8_unicode_ci not null default '0',  primary key (`id`) ) engine=myisam auto_increment=8 default charset=utf8 collate=utf8_unicode_c  forum_posts create table `forum_posts` (  `id` int(11) not null auto_increment,  `category_id` int(11) not null,  `topic_id` int(11) not null,  `post_creator` int(11) not null,  `post_content` text collate utf8_unicode_ci not null,  `post_date` datetime not null,  primary key (`id`) ) engine=myisam auto_increment=6 default charset=utf8 collate=utf8_unicode_c 


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -