我收到此错误:
错误:INSERT INTO用户(用户名,密码,邮件,余额, depost1,depost2,depost3)VALUES(测试, 4f4dfc9a3bec784d456fafabc725977e,test @ test.test,' 0',' 0',' 0',' 0') 您的SQL语法有错误;检查手册 对应于您的MariaDB服务器版本,以获得正确的语法 靠近' @ test.test,' 0',' 0',' 0',' 0')'在2号线。
所以,我查看了我的语法,但我找不到任何错误的东西。这是我的代码:
<?php
inculde('config.php');
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO users (username, password, mail, balance, depost1, depost2, depost3)
VALUES ($user, $result, $mail, '0', '0', '0', '0')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
答案 0 :(得分:1)
您错过了查询中的引号
<?php
inculde('config.php');
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO users (username, password, mail, balance, depost1, depost2, depost3)
VALUES ('$user','$result', '$mail', '0', '0', '0', '0')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
答案 1 :(得分:0)
在查询中使用值中的单引号
$sql = "INSERT INTO users (username, password, mail, balance, depost1, depost2, depost3) VALUES ('$user', '$result', '$mail', '0', '0', '0', '0')"
答案 2 :(得分:0)
将变量直接放在字符串中时,它们不会自动用引号括起来,即使它们是字符串。
您必须将查询更改为以下内容:
$sql = "INSERT INTO users (username, password, mail, balance, depost1, depost2, depost3) VALUES ('$user', '$result', '$mail', '0', '0', '0', '0')";