0

需要有关我的 php 代码的帮助,我收到此错误:

警告:mysqli_stmt::bind_param() [mysqli-stmt.bind-param]:变量数与第 18 行 C:\wamp\www\test\forum.php 中准备好的语句中的参数数不匹配。

这是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

4

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'";

现在,您将参数绑定到此查询。

于 2013-07-14T13:31:23.320 回答