gpt4 book ai didi

php - PHP Mysql中的SQL语法错误

转载 作者:太空宇宙 更新时间:2023-11-03 10:58:03 26 4
gpt4 key购买 nike

我的 php 脚本中出现以下行的 sql 语法错误

mysqli_query($con, "INSERT INTO 'rates_{$tablename}' (Weight, CBMMin, CBMMax) VALUES (".$row['weight'].",".$row['cbm_min'].",".$row['cbm_max'].");");

错误:

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 ''rates_woop' (Weight, CBMMin, CBMMax) VALUES (1000,0.1,2.3)' at line 1

变量 $con 是我的连接,工作正常

$tablename 只是一个字符串

$row[''] 是结构如下的数组中的一行

$rows = array(
array('weight' = > 1000, 'cbm_min' = > 0.1, 'cbm_max' = > 2.3),
array('weight' = > 1500, 'cbm_min' = > 2.31, 'cbm_max' = > 3.5),
array('weight' = > 2000, 'cbm_min' = > 3.51, 'cbm_max' = > 4.6),
array('weight' = > 2500, 'cbm_min' = > 4.61, 'cbm_max' = > 5.75),
array('weight' = > 3000, 'cbm_min' = > 5.75, 'cbm_max' = > 6.9),
array('weight' = > 3500, 'cbm_min' = > 6.91, 'cbm_max' = > 8));

所以查询在foreach循环中

最佳答案

不要引用表名:

mysqli_query($con, "INSERT INTO rates_{$tablename} (Weight, CBMMin, CBMMax) VALUES (".$row['weight'].",".$row['cbm_min'].",".$row['cbm_max'].")");

如果需要,请使用 `:

mysqli_query($con, "INSERT INTO `rates_{$tablename}` (Weight, CBMMin, CBMMax) VALUES (".$row['weight'].",".$row['cbm_min'].",".$row['cbm_max'].")");

关于php - PHP Mysql中的SQL语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18504908/

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