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

2024-05-21

我有一个带有 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, [email protected] /cdn-cgi/l/email-protection, 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, [email protected] /cdn-cgi/l/email-protection, eb69' at line 2

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


您的字符串值缺少引号:

$sql = "INSERT INTO people (person_id, name, username, password, email, salt)
            VALUES ($person_id, '$name', '$username', '$password', '$email', '$salt')";
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用php插入sql数据库时出错 的相关文章