1

忍受我,我意识到有很多关于这个错误的帖子。但是我浏览了它们,似乎无法找到解决我特定问题的方法。

我试过“isi”、“sss”和“sii”不起作用。不知道该怎么做任何帮助都会很棒。

不太确定在哪里使用 var_dump(); 了解有关我的问题的更多信息。我对 PHP 很陌生,知道这也会有很大帮助。

谢谢你陪我!抱歉有重复的话题。

代码:

<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;

这一行:

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();
?>
4

1 回答 1

1

您的查询准备包含零个参数,因为您只是将值转储在那里,完全违背了准备语句的目的。相反,试试这个:

 if (!($stmt = $mysqli->prepare("INSERT INTO table(id, name, votes) VALUES (?,?,?)"))) {

然后照常继续。

于 2013-04-06T23:25:35.840 回答