Php 非对象错误上的成员函数bind_param()

Php 非对象错误上的成员函数bind_param(),php,function,Php,Function,我简直目瞪口呆。有什么问题?我已经从复制了默认的PHP OOS,它不断抛出错误 <?php $mysqli = new mysqli('localhost', 'root', 'hidden', 'hidden'); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $stmt = $

我简直目瞪口呆。有什么问题?我已经从复制了默认的PHP OOS,它不断抛出错误

<?php
$mysqli = new mysqli('localhost', 'root', 'hidden', 'hidden');

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

$stmt = $mysqli->prepare("INSERT INTO users VALUES (?, ?)");
$stmt->bind_param('ss', $name, $password);

$name = "Test";
$password = "Test";

/* execute prepared statement */
$stmt->execute();

printf("%d Row inserted.\n", $stmt->affected_rows);

/* close statement and connection */
$stmt->close();

/* close connection */
$mysqli->close();
?>

致命错误:对中的非对象调用成员函数bind_param() 第11行的C:\xampp\htdocs\cms\index.php

更改这些行:(在用户表中插入2个字符串参数时)

with:(我假设您必须插入名称和密码字段……如果没有,请使用您适当的字段名称作为名称和密码)


为什么您要在
bind_param
中传递4个参数?您好,谢谢您的回复。然而,这并没有起作用。致命错误:对第11行C:\xampp\htdocs\cms\index.php中的非对象调用成员函数bind_param(),仍存在stmt准备检查。。。
$stmt = $mysqli->prepare("INSERT INTO users VALUES (?, ?)");
$stmt->bind_param('sssd', $name, $password);
if (!($stmt = $mysqli->prepare("INSERT INTO users(name,password) VALUES (?, ?)"))) {
    echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
$stmt->bind_param('ss', $name, $password);