问题
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