doutinghou6980 2013-04-06 23:23
浏览 87
已采纳

警告:mysqli_stmt :: bind_param()变量数与预准备语句中的参数数量不匹配

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. Not sure what to do any help would be great.

Not too sure where to use var_dump(); to find out more information about my problem. I'm pretty new to PHP that would help a lot too, to know.

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();
?>
  • 写回答

1条回答 默认 最新

  • doutuo7126 2013-04-06 23:25
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改