//Successful connection to $db
function insert_users($db, $username, $password, $email)
{
echo "FUNCTION CALLED"; //This is outputted successfully
$query = "INSERT INTO `users` (`id`, `username`, `password`, `email`) VALUES ('', ?, ?, ?)";
$stmt = mysqli_stmt_init($db);
if(mysqli_stmt_prepare($stmt, $query))
{
echo "QUERY PREPARED"; // rest of code was snipped (will put up upon request)
} else {
echo "QUERY DENIED"; //This is outputted successfully
}
}
//The $user $pass and $mail are defined and then the function is called
insert_users($db, $user, $pass, $mail);
数据库结构:
testdb (database)
-> users (table)
-> id //Primary key, unique key
-> username //unique key
-> password
-> email
为什么查询不通过它的操作?它回显“查询被拒绝”而不是“查询准备”。我相信该查询无效。如果需要更多信息,很乐意编辑此问题
编辑
我添加了
mysqli_stmt_error($stmt);
什么都没有发生之后echo "QUERY DENIED";
……
编辑 2
$server = 'localhost';
$user = 'root';
$password = '';
$databse = 'testdb';
$db = @mysqli_connect($server, $user, $password, $database) or die("Could not connect to Database server. Please inform an administrator");
这是我的数据库设置。我是否将变量放在引号中?