Not updating sql db script


I have the following code (or similar) in multiple pages on my site


$result = mysql_query(“UPDATE table SET $blah WHERE $here”);


In all cases this does nothing. There is no update. I know the table has elements in it that would make it update, but …

Please help


Print your query to the screen and run it by hand using command line or phpMyAdmin(or something else if you have it). Or echo mysql_error() after the query and see what happened.


with mysql_error() it prints

Unknown column ‘$user_name’ in ‘where clause’

What does this mean


Can I have one of columns to be set be a varible? The thing is under curtain conditions I need to be col1 then col2 then…

I currently have this

$result = mysql_query(“UPDATE active SET $prog_num = $quote … WHERE sym = $sym”);

Can I do this with $prog_num? What is the right way of doing it?



For basic database manipulation (insert, update, delete, etc.) the “Creating Dynamic Websites with PHP and MySQL” at in the tutorials/basics section is a great primer.

Your error means that you are asking it to find a column that is not in the table you gave it. And yes you can definately have 1 column equal a variable. If you would like a couple of links on learning SQL let me know.


This is the syntax of update.

UPDATE tablename SET column1=value, column2=value, column3=value … WHERE condition


UPDATE employee SET Lastname=‘Jones’, Firstname=‘Joe’ WHERE Idnum = 123


UPDATE employee SET Lastname=’$lname’, Firstname=’$fname’ WHERE Idnum=$num

  • You could update all the column in the table, just separate them with a comma.