Prepared statement help, Number of variables doesn't match number of parameters in prepared statement

谁都会走 提交于 2019-12-11 00:04:25

问题


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);


来源:https://stackoverflow.com/questions/4633120/prepared-statement-help-number-of-variables-doesnt-match-number-of-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!