Reputation: 2763
I have a mysql query as follows :
$sql = "
INSERT INTO
tbl_stopage
SET
bus_id = '$bid',
stopage_name = '$info[stopage_name]',
fare = '$info[fare]',
from = 'Ghy'
";
But when I tried to execute the above query , it shows the following error :
DB 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 'from = 'Ghy'' at line 7
INSERT INTO tbl_stopage SET bus_id = '1', stopage_name = 'Dergaon', fare = '123', from = 'Ghy'
Upvotes: 0
Views: 47
Reputation: 7438
$sql = "INSERT INTO
tbl_stopage (`bus_id`,`stopage_name`,`fare`,`from`)
VALUES ('$bid','$info[stopage_name]','$info[fare]','Ghy')";
But it's better to use prepared statements.
Upvotes: 1
Reputation: 35343
in SQL FROM is a reserved word try using from
with the proper mySQL escape characters which I believe is `.
In addition, are all the "numeric" values actualy numbers in the database? if so you don't need the tics (') around them.
Overall if its not too late you may avoid future headaces simply by altering the table not to use keywords such as FROM, SELECT, WHERE, GROUP BY, ORDER BY etc.
Upvotes: 4