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.

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

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?