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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog