Page 1 of 1

troblesome insert statement

Posted: Tue Oct 20, 2009 12:52 pm
by misho
hi guys,
i would really appreciate if you help me with the following problem:

i'm still getting an syntax error message (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 '' at line 1) while executing this statement out of PHP:
INSERT INTO chezelle.products (prod_no,prod_desc_eng,prod_desc_svk,main_cat_id,sub_cat_id,color_eng,color_svk,size,material_eng,material_svk,price,in_stock,pieces_in_stock,pic_small,pic_large) VALUES('1050','dkssqpdkqpdkqpdk','dqwkdpoqkdpoqkd',1,2,'dqkdpoqkpdkqpkp','dqdkqpdkqpodkqd','dkdkapd','dqkdpqkdqp','dqkdqpdkq',15,'n',0,'thumbs/ART-NR.1030_t.jpg','ART-NR.1030.jpg')

In fact, what surprises me is that the insert statement gets executed and there is a new row in the table after the execution of the code, but i still cannot get rid of the error statement.
when i execute the same statement out of phpmyadmin it also executes without a problem.

i'm using the following code:

Code: Select all

$insert_new_query = "INSERT INTO $db_id.products (prod_no,prod_desc_eng,prod_desc_svk,main_cat_id,sub_cat_id,color_eng,color_svk,size,material_eng,material_svk,price,in_stock,pieces_in_stock,pic_small,pic_large)
VALUES('$prod_no','$prod_desc_eng','$prod_desc_svk',$main_cat_id,$sub_cat_id,'$color_eng','$color_svk','$size','$material_eng','$material_svk',$price,'$in_stock',$pieces_in_stock,'$pic_small','$pic_large')";
 
mysql_query($insert_new_query) or die('Error:'.mysql_error());
I enclose strings into '' and leave the numeric value unenclosed.

any ideas?

Re: troblesome insert statement

Posted: Wed Oct 21, 2009 10:14 am
by misho
hm, i tried everything that came across my mind, currently the query form has changed to:

Code: Select all

$insert_new_query = "INSERT INTO `products` (`prod_no`,`prod_desc_eng`,`prod_desc_svk`,`main_cat_id`,`sub_cat_id`,`color_eng`,`color_svk`,`size`,`material_eng`,`material_svk`,`price`,`in_stock`,`pieces_in_stock`,`pic_small`,`pic_large`) VALUES ('$prod_no','$prod_desc_eng','$prod_desc_svk','$main_cat_id','$sub_cat_id','$color_eng','$color_svk','$size','$material_eng','$material_svk','$price','$in_stock','$pieces_in_stock','$pic_small','$pic_large')";
that means i enclosed column names within `` quotes and every value (no matter if string or numeric within single quotes and moreover i placed the whole query on a single line, but nothing helped. the behavior is still the same: the row gets inserted into the table but the error keeps displaying on the page :(

please help if you can..

Re: troblesome insert statement

Posted: Wed Oct 21, 2009 10:48 am
by misho
:D happy to announce that the issue is fixed! i was just not looking in the right place. in fact it was the execution of another query that was failing - the code proceeded to the part i did not expect it to proceed and executed another query without variables set and that produced the error :)