Sam Jackson
Sam Jackson

Reputation: 628

UPDATE MySQL Syntax Error

I am getting an SQl syntax error when running the following query and can not see what is wrong with it:

$query = "UPDATE combined SET v_categories_name_1_1='Hoodie', 
v_attribute_options_id_1=1, v_attribute_values_id_1_1=1, v_attribute_values_id_1_2=2, 
v_attribute_values_id_1_3=3, v_attribute_values_id_1_4=4, 
v_attribute_values_price_1_1=0, v_attribute_values_price_1_2=0, 
v_attribute_values_price_1_3=0, v_attribute_values_price_1_4=0, 
v_attribute_options_name_1_1='Size', v_attribute_values_name_1_1_1='Small', 
v_attribute_values_name_1_2_1='Medium', v_attribute_values_name_1_3_1='Large', 
v_attribute_values_name_1_4_1='Extra Large') " .
"WHERE v_products_model='$fileName'";

And here is the 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 ') WHERE v_products_model=hs_3stm_giantsk.jpg' at line 1

UPDATE:

Thanks everyone for the super fast replies, it's solved my problem though unfortunately I can't accept them for another 9 minutes!

Upvotes: 1

Views: 264

Answers (6)

kitti
kitti

Reputation: 14814

Try formatting your queries; problems become much more apparent:

$query = "
    UPDATE combined SET 
        v_categories_name_1_1='Hoodie', 
        v_attribute_options_id_1=1,
        v_attribute_values_id_1_1=1,
        v_attribute_values_id_1_2=2, 
        v_attribute_values_id_1_3=3, 
        v_attribute_values_id_1_4=4, 
        v_attribute_values_price_1_1=0, 
        v_attribute_values_price_1_2=0, 
        v_attribute_values_price_1_3=0,
        v_attribute_values_price_1_4=0, 
        v_attribute_options_name_1_1='Size',
        v_attribute_values_name_1_1_1='Small', 
        v_attribute_values_name_1_2_1='Medium', 
        v_attribute_values_name_1_3_1='Large', 
        v_attribute_values_name_1_4_1='Extra Large')
    WHERE v_products_model='$fileName'
";

That bad paren is much easier to notice when you're not just looking at one big blob of text. You would (hopefully) never write PHP like that, so why write your SQL like that?

Upvotes: 3

Maksym Polshcha
Maksym Polshcha

Reputation: 18358

Enclosing bracket with no opening one here

='Extra Large')

Upvotes: 2

Karo
Karo

Reputation: 744

Try this

$query = "UPDATE combined SET v_categories_name_1_1='Hoodie', 
v_attribute_options_id_1=1, v_attribute_values_id_1_1=1, v_attribute_values_id_1_2=2, 
v_attribute_values_id_1_3=3, v_attribute_values_id_1_4=4, 
v_attribute_values_price_1_1=0, v_attribute_values_price_1_2=0, 
v_attribute_values_price_1_3=0, v_attribute_values_price_1_4=0, 
v_attribute_options_name_1_1='Size', v_attribute_values_name_1_1_1='Small', 
v_attribute_values_name_1_2_1='Medium', v_attribute_values_name_1_3_1='Large', 
v_attribute_values_name_1_4_1='Extra Large' " .
"WHERE v_products_model='$fileName'";

I removed the bracket before WHERE clause.

Upvotes: 2

Andrius Naruševičius
Andrius Naruševičius

Reputation: 8578

There is a symbol ) appearing for no reason :)

Upvotes: 2

dvir
dvir

Reputation: 5115

You have an odd ) at the end of the line before the last.

Upvotes: 2

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798656

You close parens that you you never open.

Upvotes: 2

Related Questions