首页 文章

mySQLi插入错误 - 调用成员函数bind_param [duplicate]

提问于
浏览
0

这个问题在这里已有答案:

我得到了这个非常简单的mysqli查询失败并返回此消息:

致命错误:未捕获错误:在M:\ xampp \ htdocs \ insert \ form-handler.php中调用boolean上的成员函数bind_param():17堆栈跟踪:在M:\ xampp \ htdocs中抛出#0 第17行\ insert \ form-handler.php

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <form action="form-handler.php" method="POST">
        <input type="text" name="firstname">
        <input type="text" name="lastname">
        <input type="submit">
    </form>
</body>
</html>

PHP:

$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];

$mysqli = new mysqli('localhost', 'root', '', 'firstlast');

if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$stmt = $mysqli->prepare('INSERT INTO users (id, firstname, lastname) VALUES ("", ?, ?');

$stmt->bind_param('ss', $firstname, $lastname);

$stmt->execute();

$stmt->close();

有什么我错过的吗?谢谢 .

1 回答

  • 0
    $stmt = $mysqli->prepare('INSERT INTO users (id, firstname, lastname) VALUES ("", ?, ?)');
    

    $stmt 删除 ! 并且您错过了 ) 以关闭 VALUES

相关问题