//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);
数据库结构:MySQLi程序查询,出了什么问题?
testdb (database)
-> users (table)
-> id //Primary key, unique key
-> username //unique key
-> password
-> email
为什么好好尝试查询经过与它的操作? 它回应“查询被拒绝”而不是“查询准备”。该查询无效,我相信。如果需要了解更多信息,虐待很乐意编辑这个问题
编辑
我加
mysqli_stmt_error($stmt);
的echo "QUERY DENIED";
没有任何反应后...
EDIT 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");
这是我的数据库设置。我是否将变量放在引号中?
请出示['mysqli_stmt_error'(http://php.net/manual/en/mysqli-stmt.error.php),当你准备失败。 –
您试图将空字符串插入主键列。你的情况合法吗?是PK自动增量? –
@Olaf Dietsche好吧,会做:) – Wulf