Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将字段动态插入表中,但查询出错_Php - Fatal编程技术网

Php 将字段动态插入表中,但查询出错

Php 将字段动态插入表中,但查询出错,php,Php,} 错误 测试了打印字段和值,它们是正确的。调用了函数add,然后在语法上出错,但无法判断查询哪里出错 密钥应包装为“而不是” Prepare failed: (1064) 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 ''name','address','country','

}

错误


测试了打印字段和值,它们是正确的。调用了函数add,然后在语法上出错,但无法判断查询哪里出错

密钥应包装为“而不是”

Prepare failed: (1064) 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 ''name','address','country','type','status') VALUES ('Starbucks','Washington ','U' at line 1

 $food->add("food", $_POST, "add");

密钥应该用“而不是”包装

Prepare failed: (1064) 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 ''name','address','country','type','status') VALUES ('Starbucks','Washington ','U' at line 1

 $food->add("food", $_POST, "add");

print\r($fields)
print\r($values)
的Post值以及列和表名中的引号会产生问题!!我认为列字段的数量与相应值的数量不匹配。因为你的错误。('name'、'address'、'country'、'type'、'status')值('Starbucks'、'Washington'、'U')@psyLogic以及列名称中的
引号
又如何呢?打印($fields)和
打印($value)
的Post值以及列和表名称中的引号都会产生问题!!我认为列字段的数量与相应值的数量不匹配。因为你的错误。('name'、'address'、'country'、'type'、'status')值('Starbucks'、'Washington'、'U')@psyLogic和列名称中的
quotes
如何??“做什么?”@joe read哦“做什么?”@joe read
$fields[] = "`$key`";