我在导师提供的以下代码方面遇到了一些问题但是我在使用它时遇到了一些麻烦。
我收到此错误:
“无效的对象或资源mysqli_stmt”
这是我的代码,它从之前的html文件输入的文本中获取数据,然后将该数据发送到我的数据库:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL | E_STRICT);
//Report all errors or strict errors
//<USERNAME> and <PASSWORD> are temporary for this post.
$database = mysqli_connect("localhost", "<USERNAME>", "<PASSWORD>") or
die ('Unable to connect. Check connection params');
$userName = $_POST['userName'];
$password = $_POST['password'];
$emailAddress = $_POST['emailAddress'];
if ($database != FALSE)
{
print "Connection to the database made successfully.";
echo $userName;
echo $password;
echo $emailAddress;
$query = "INSERT INTO customerData(userName, password, emailAddress) VALUES (?,?,?)";
$stmt = mysqli_stmt_init($database);
mysqli_stmt_prepare($stmt, $query);
mysqli_stmt_bind_param($stmt, 'isii', $userNamename, $password, $emailAddress);
mysqli_stmt_execute($stmt);
print "user added.";
}
?>
答案 0 :(得分:1)
不确定脚本有什么问题。
if($database != FALSE)
很容易
if($database)
答案 1 :(得分:0)
mysqli_stmt_bind_param($stmt, 'isii', $userNamename, $password, $emailAddress);
'isii'
指定了太多项目。
我认为你的意思是:
mysqli_stmt_bind_param($stmt, 'sss', $userNamename, $password, $emailAddress);
参考:http://us.php.net/manual/en/mysqli-stmt.bind-param.php#refsect1-mysqli-stmt.bind-param-parameters