I have the below mysql statement:
INSERT INTO rates_try (`Weight`, `length`, `height`, `Min`, `100`, `200`, `300`) VALUES (1000,0.1,2.3,1,2,3,4);
Which gives the error:
No Row created. Check 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 'insertquery' at line 1INSERT INTO rates_try (
Weight
,length
,height
,Min
,100
,200
,300
) VALUES (1500,2.31,3.5,1,0,0,0);
The table structure is:
rates_try ( `Weight` int(11),
`length` double,
`height` double,
`Min` double,
`100` double,
`200` double,
`300` double )
I am not sure what is wrong with the syntax and I know it most likely have something to do with the columns being numbers, if this is the issue causing it I will have to add something to the names so they are not just numbers, but I wanted to check that this was not the case first.
THe php code that creates the statement
$insertquery = "INSERT INTO rates_{$tablename} (`Weight`, `length`, `height`, `Min`";
foreach ($titles as $title){
if (empty($title) ){
}else{
$insertquery .= ", `" . $title . "`";
$counter++;
}
}
$insertquery .= ") VALUES (".$row['weight'].",".$row['cbm_min'].",".$row['cbm_max'].",".$value;
$a = 0;
while ($a < $counter){
$newvalue = $array[$a][$i];
if (empty($newvalue)){
$newvalue = 0;
}
$insertquery .= ",". $newvalue;
$a++;
}
$insertquery .= ");";
echo $insertquery. "<br/>";
$queryResult = mysqli_query($con, insertquery);
$queryResult = mysqli_query($con, insertquery);
Can you see it now?
(there's a missing $
in front of insertquery
)
This is an interesting one, as you have actually followed the rules about using backticks to surround column names - and according to the document I just checked, your column names ARE indeed valid:
Identifiers may begin with a digit but unless quoted may not consist solely of digits.
On that note, while MySQL identifiers on Windows are not case sensetive, you will find that on Linux, they ARE. Are you sure that you haven't missed an upper or lower case somewhere? Your first column uses an upper case to start, but none of the others do.
I will however say that using column names that must be back-ticked is generally a BAD idea. Use something that doesn't need special care each and every time you refer to it.