本文介绍了PHP mysqli_query语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码有问题.我认为这很好,但是控制台说不是:
I have a problem with my code. I think it's good but the console says its not:
这是代码:
$result = mysqli_query($con, "INSERT INTO users SET (email, username, encrypted_password, salt, created_at) VALUES('$email', '$uname', '$encrypted_password', '$salt', NOW())");
推荐答案
您的查询不正确.尝试如下:
Your query is incorrect. Try as below :
$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;
}
参考文献:
- http://php.net/manual/en/function.mysqli- connect.php
- http://php.net/manual/en/mysqli.query.php
- http://php.net/manual/en/mysqli.error.php
- http://dev.mysql.com/doc/refman/5.7/en/insert.html
- http://php.net/manual/en/function.mysqli-connect.php
- http://php.net/manual/en/mysqli.query.php
- http://php.net/manual/en/mysqli.error.php
- http://dev.mysql.com/doc/refman/5.7/en/insert.html
这篇关于PHP mysqli_query语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!