gpt4 book ai didi

php - MySQL INSERT 语法错误,不确定原因

转载 作者:行者123 更新时间:2023-11-29 05:17:55 25 4
gpt4 key购买 nike

我的 PHP 查询出现以下错误:

有人知道为什么吗?它传递了一个电子邮件地址,但从错误看来它在那里中断了,但我可能是错的。

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 'INSERT INTO customers SET name = "James Brandon", email = "james@ambient' at line 10

PHP

$query .= "INSERT INTO customers SET
name = '".$customer_name."',
email = '".$customer_email."',
address_1 = '".$customer_address_1."',
address_2 = '".$customer_address_2."',
town = '".$customer_town."',
county = '".$customer_county."',
postcode = '".$customer_postcode."',
phone = '".$customer_phone."',

name_ship = '".$customer_name_ship."',
address_1_ship = '".$customer_address_1_ship."',
address_2_ship = '".$customer_address_2_ship."',
town_ship = '".$customer_town_ship."',
county_ship = '".$customer_county_ship."',
postcode_ship = '".$customer_postcode_ship."';
";

最佳答案

INSERT 语句的两种可能语法。在以下第一种情况下,您仅指定要填充的列。

INSERT INTO TABLE (COL1, COL2, COL3)
VALUES (VAL_COL1, VAL_COL2, VAL_COL3);

您也可以在不提供 col_name 的情况下进行 INSERT,但您必须指定所有列的值并且良好顺序

我认为第一个选项更好,它会避免你犯很多错误,尤其是当你的表中有很多不同的列时。

关于php - MySQL INSERT 语法错误,不确定原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30094849/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com