2013-07-14 75 views
0

需要我的PHP代碼的幫助,我得到這個錯誤:PHP代碼,(數據庫,論壇)錯誤

Warning: mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: Number of variables doesn't match number of parameters in prepared statement in C:\wamp\www\test\forum.php on line 18.

這是forum.php:

<?php 
session_start(); 
require"db_connect.php"; 
//get the page id 
if(isset($_GET['id'])&&is_numeric($_GET['id'])){ 
     $id = $_GET['id']; 
} else { 
    die("Error"); 
} 
//check 
$idCheck = $db->query("SELECT * FROM forum_tabl WHERE forum_id = '$id'"); 
if($idCheck->num_rows !==1){ 
    die("error"); 
} 
$row = $idCheck->fetch_object(); 
$sql = "SELECT post_id, post_title FROM forum_post WHERE forum_id=1 AND post_type='o'"; 
if($query = $db->prepare($sql)){ 
    $query->bind_param('s',$id); 
    $query->bind_result($post_id, $post_title); 
    $query->execute(); 
    $query->store_result(); 
}else{ 
    echo $db->error; 
} 

?> 
<!doctype html> 
<html> 
<head> 
<meta charset="utf-8"> 
<title><?php echo $row->forum_name?></title> 
</head> 

<body> 
<div id="container"> 
    <table width="80%"> 
     <?php if($query->num_rows!=0):?> 
     <?php while ($query->fetch()):?> 
     <tr> 
      <td><?php echo $post_title?></td> 
     </tr> 
     <?php endwhile;?> 
     <?php else:?> 
     <tr> 
      <td><h2>No Posts Found</h2></td> 
     </tr> 
     <?php endif;?> 
    </table> 
</div> 
</body> 
</html> 


這是現在的樣子:http://wildmine.tk/test/forum.php?id=1

+1

你似乎沒有在你的查詢中使用任何參數? –

回答

2
$sql = "SELECT post_id, post_title FROM forum_post WHERE forum_id=1 AND post_type='o'"; 

應該是

$sql = "SELECT post_id, post_title FROM forum_post WHERE forum_id= ? AND post_type='o'"; 

現在,您將綁定您的參數到此查詢。

+0

我怎麼看不到,謝謝! – Wildmine

+0

沒問題,隨時:) –