PHP "INSERT INTO"不工作

标签 php mysql mysqli get

<分区>

我正在尝试使用 PHP 的“INSERT INTO”函数,但由于某些未知原因,它无法正常工作。

这是代码的主要部分 -

$sql = "INSERT INTO order (t_from, t_to, t_date, t_time, t_payment, t_sn, t_u_email) 
        VALUES ('a', 'b', 'c', 'd', 'e', 'f', 'g')";

这有什么问题吗?

请帮忙!

谢谢,

最佳答案

order 是 MySQL 的保留关键字。

http://dev.mysql.com/doc/mysqld-version-reference/en/mysqld-version-reference-reservedwords-5-0.html

要么将 order 更改为其他内容,

或者在 order 周围加上反引号。

$sql = "INSERT INTO `order` (t_from, t_to, t_date, t_time, t_payment, t_sn, t_u_email) 
        VALUES ('a', 'b', 'c', 'd', 'e', 'f', 'g')";

另一种解决方案是在表名之前使用数据库名。

$sql = "INSERT INTO DB_NAME.order (t_from, t_to, t_date, t_time, t_payment, t_sn, t_u_email) 
            VALUES ('a', 'b', 'c', 'd', 'e', 'f', 'g')";

关于PHP "INSERT INTO"不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27104224/

相关文章:

php - "Mysql expects parameter 2 to be integer, string given in"错误类型

php - 无法连接到数据库

javascript - 对 JSON 数据运行 jQuery

javascript - 如何将php数据传递给kinetic js

php - 如何在 Laravel 5.7 中翻译密码重置电子邮件?

php - 如何使用 php 脚本导出完整的 mysql 数据库...?使用 'mysqldump' 时出现问题

mysql - 错误消息 : Unable to get connection, 数据源无效: "java.sql.SQLException: Cannot create JDBC driver of class ' ' 对于连接 URL 'null' ”

php - 命令不同步;你现在不能运行这个命令

php - Javascript 或 Jquery : Getting key inputs without focus

mysql - 如何创建一对多关系,以便一篇博客文章可以有多个类别