Prepared statement help, Number of variables doesn

2019-07-23 13:14发布

问题:

I'm getting this error : Number of variables doesn't match number of parameters in prepared statement every time I run this code:

$dbh = new mysqli("localhost", "***", "***", "pics");
    $stmt = $dbh->prepare("INSERT INTO comments (username, picture, comment) VALUES (?, ?, ?)");
   $stmt->bind_Param('s', $username);
   $stmt->bind_Param('d', $picture);
   $stmt->bind_Param('s', $comment);

   $username=$_SESSION['username'];
   $picture=$_GET['id'];
   $comment=$_POST['comment'];
   $stmt->execute();

What's the problem?

回答1:

Try putting all the parameters into one bindParam call:

$stmt->bind_Param('sds', $username, $picture, $comment);