Wildmine
Wildmine

Reputation: 1

php code, (database, forum) error

Need help with my php code, i get this error:

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.

This is the 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>


And this is how it looks now: http://wildmine.tk/test/forum.php?id=1

Upvotes: 0

Views: 123

Answers (1)

Darius Donisanu
Darius Donisanu

Reputation: 80

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

should be

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

Now, you will bind your parameter to this query.

Upvotes: 2

Related Questions