Using mysql update with variables

Hi I have a table with one row and twelve fields all named 1 to 12.
I am trying to update one field to NULL. I can do this when not using any variables for the table name, field name etc but once I use variables I cant get it to work. My table is set up to accept null values.
I have tried an endless number of variations and scoured the internet but nothing seems to work.
This was my latest attempt at 1am but still get error messages.

[php]$sql2 = “UPDATE ‘$table’ SET ‘$field’ = NULL WHERE ID= 1”;[/php]

Thanks in advance

Chipie

You use backticks not quotes for table and column names

[php]$sql2 = “UPDATE $table SET $field = NULL WHERE ID = 1”;[/php]

Hi M@tt, I have tried that and got an error:

Unknown column ‘ID’ in ‘where clause’

Cheers for suggestion though!

Chipie

I finally solved the problem and thought I would post it anyway incase anybody else was in the same boat as me.

[php]sql2 = “UPDATE “.$resetTable.” SET 1 = NULL WHERE ID= $fixed”;[/php]

The problem was that my fields are named after numbers and not strings. Therefore you must surround the number with ticks (``) for it to be treat as a row and not a number.

Sponsor our Newsletter | Privacy Policy | Terms of Service