Not updating sql db script

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

[php]

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

[/php]

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

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

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

Thanks

For basic database manipulation (insert, update, delete, etc.) the “Creating Dynamic Websites with PHP and MySQL” at http://www.codewalkers.com 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

EXAMPLE

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

OR

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.
Sponsor our Newsletter | Privacy Policy | Terms of Service