Click to See Complete Forum and Search --> : Mysql query shows strange error


laura81
10-04-2008, 02:26 PM
Hello!

I have a problem with my sql query. The query itself is following:
$result=dbquery("INSERT INTO ".$db_prefix."table1 VALUES('', $data_group_id, $data_contact_id, $data_code, $data_name, $data_status)");

When I execute it, it doesn't add records to database and shows error like this:

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 ' OK, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,' at line 1

I have checked that all my database fields exist in the right order, database fields are all text or varchar.

I have used queries like that lots of times, but have never had any errors. :(
Where could I start solving the problem?

Thank you in advance,
Laura :)

chazzy
10-04-2008, 03:04 PM
if you don't use a db binding technique, you need to wrap each field in the insert in single quotes. like this:


$result=dbquery("INSERT INTO ".$db_prefix."table1 VALUES('', '$data_group_id', '$data_contact_id', '$data_code', '$data_name', '$data_status')");

laura81
10-04-2008, 03:10 PM
Thank you chazzy. Really stupid of me to not notice that.:o