0

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'

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks xQbert, I changed from to source_station and it worked.
1
$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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.