I have been getting a sql syntax error with the below line in my php script
mysqli_query($con, "INSERT INTO 'rates_{$tablename}' (Weight, CBMMin, CBMMax) VALUES (".$row['weight'].",".$row['cbm_min'].",".$row['cbm_max'].");");
The error:
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
the variable $con
is my connection which works fine
$tablename
is just a string
$row['']
is a row from an array structured like below
$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));
So the query is within a foreach loop
backtick
character ( ` ) – hallaji Aug 29 '13 at 7:42