我的代码有问题。我认为这很好,但控制台说它不是:
警告:mysqli_query()要求参数1为mysqli,在 /home/u772833821/public_html/DB_Functions.php 66
中给出null
以下是代码:
$result = mysqli_query($con, "INSERT INTO users SET (email, username, encrypted_password, salt, created_at) VALUES('$email', '$uname', '$encrypted_password', '$salt', NOW())");
答案 0 :(得分:2)
您的查询不正确。请尝试以下方法:
$result = mysqli_query($con, "INSERT INTO users (email, username, encrypted_password, salt, created_at) VALUES('$email', '$uname', '$encrypted_password', '$salt', NOW())");
尝试检查$con
是否有效:
$host = "your_host"; // replace these settings for your own
$username = "your_username";
$password = "your_password_if_any";
$db = "your_db_name";
$con = mysqli_connect($host, $username, $password, $db);
if (!$con) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
参考文献:
答案 1 :(得分:0)
请按照步骤操作,还有一个更正:
1。从INSERT查询中删除SET
$result = mysqli_query($con, "INSERT INTO users (email, username, encrypted_password, salt, created_at) VALUES('$email', '$uname', '$encrypted_password', '$salt', NOW())");
2. 检查连接错误
$con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
if (!$con) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
也许连接问题。让我知道点 2 的输出是什么。