php - 使用php插入sql数据库时出错

标签 php mysql syntax-error sql-insert mysql-error-1064

我有一个带有 MySQL 插入查询的程序:

        $sql = "INSERT INTO people (person_id, name, username, password, email, salt)
                VALUES ($person_id, $name, $username, $password, $email, $salt)";
        if ($con->query($sql) === TRUE) {
            successful();
        } else {
            unsuccessful("Error: " . $sql . "<br>" . $con->error);
        }

当我运行代码时出现此错误:

Error: INSERT INTO people (person_id, name, username, password, email, salt) VALUES (2, Tom Jack, tjack95, 8a01fc598a676a249c5844bd3baf4f4d83cecdf2, tom@tommy.com, eb694539989fda2e17f79e70fb306f8911c3dee5)
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Jack, tjack95, 8a01fc598a676a249c5844bd3baf4f4d83cecdf2, tom@tommy.com, eb69' at line 2

sql 插入对我来说看起来完全没问题。有什么问题?

最佳答案

您的字符串值周围缺少引号:

$sql = "INSERT INTO people (person_id, name, username, password, email, salt)
            VALUES ($person_id, '$name', '$username', '$password', '$email', '$salt')";

关于php - 使用php插入sql数据库时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26553350/

相关文章:

html - Uncaught SyntaxError : Unexpected token < in HTML - can't solve

javascript - 修改函数,如果两个参数都为 true,则返回 true,否则返回 false

php - 在用户注册中添加了自定义字段,但该字段不会将信息推送到数据库

php - GAE - 如何从 php 获取谷歌云存储对象的上次修改/重命名日期时间

php - KCFinder with CKEditor - 为上传文件设置动态文件夹

php - 如何在MySQL中使用LIKE?

MySQL:整数值和字符串字段与索引的比较

php - regex preg php 中的 [^>] 是什么意思?

php - 教义中的并发

Jquery 如果文本框>0