[英]Warning: mysqli_stmt::bind_param() Number of variables doesn't match number of parameters in prepared statement
Bear with me I realize there are many posts about this error. 忍受我,我知道有很多关于此错误的文章。 But I have looked through them and can't seem to find the solution for my particular problem.
但是我已经仔细检查了它们,但似乎找不到我特定问题的解决方案。
I have tried "isi", "sss", and "sii" doesn't work. 我尝试了“ isi”,“ sss”和“ sii”不起作用。 Not sure what to do any help would be great.
不知道该怎么做会很好。
Not too sure where to use var_dump(); 不太确定在哪里使用var_dump(); to find out more information about my problem.
找出有关我的问题的更多信息。 I'm pretty new to PHP that would help a lot too, to know.
我对PHP还是很陌生,这对我很有帮助。
Thanks for bearing with me! 感谢您的支持! Sorry about a repeat topic.
很抱歉重复一个话题。
code: 码:
<tr>
<form action="Voting_action.php" method="post">
<td><br />
<input type="submit" class="buttontable1" value="<?php echo $random; ?>" name="name"/>
</td>
</form>
<form action="Voting_action.php" method="post">
<td><br />
<input type="submit" class="buttontable1" value="<?php echo $random3; ?>" name="name"/>
</td>
</form>
</tr>
<tr>
<form action="Voting_action.php" method="post">
<td><br />
<input type="submit" class="buttontable1" value="<?php echo $random6; ?>" name="name"/>
</td>
</form>
<form action="Voting_action.php" method="post">
<td><br />
<input type="submit" class="buttontable1" value="<?php echo $random4; ?>" name="name"/>
</td>
</form>
</tr>
<tr>
<form action="Voting_action.php" method="post">
<td><br />
<input type="submit" class="buttontable1" value="<?php echo $random5; ?>" name="name"/>
</td>
</form>
<form action="Voting_action.php" method="post">
<td><br />
<input type="submit" class="buttontable1" value="<?php echo $random2; ?>" name="name"/>
</td>
</tr>
<?php
include ('login-home.php');
$mysqli = new mysqli("", "", "", "");
if ($mysqli->connect_error) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_error . ") " . $mysqli->connect_error;
}
if (!($stmt = $mysqli->prepare("INSERT INTO table(id, name, votes) VALUES (id, '".$_POST['name']."', '".$votes."')"))) {
echo "Prepare failed: (" . $mysqli->error . ") " . $mysqli->error;
}
$id = 1;
This line: 这行:
if (!$stmt->bind_param("isi",$id, $_POST['name'], $votes)) {
echo "Binding parameters failed: (" . $stmt->error . ") " . $stmt->error;
}
if (!$stmt->execute()) {
echo "Execute failed: (" . $stmt->error . ") " . $stmt->error;
}
$stmt->close();
?>
Your query preparation contains zero parameters, since you just dumped the values in there, completely defeating the purpose of prepared statements. 您的查询准备包含零个参数,因为您只是将值转储到那里,从而完全违反了准备好的语句的目的。 Instead, try this:
相反,请尝试以下操作:
if (!($stmt = $mysqli->prepare("INSERT INTO table(id, name, votes) VALUES (?,?,?)"))) {
Then continue as you are. 然后照原样继续。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.