Wondering.....can you pass a variable to the column name in an UPDATE query? I can't get this to work, tried a few different combinations. I've confirmed the variable $category gives output (by inserting an echo command).....
The code in question is:
$query = "UPDATE items SET '$category' = '$updatevalue' WHERE id = '$id'";
If I insert the column name to update (breakfast) in place of the '$category' like so:
$query = "UPDATE items SET breakfast = '$updatevalue' WHERE id = '$id'";
it works fine.....I must be doing something wrong! Thanks in advance....
Scott
The whole code is:
$user="user";
$host="xxxxxx";
$password="";
$database="newfood";
$category="breakfast";
$connection = mysql_connect($host,$user,$password)
or die ("couldn't connect to server");
$db = mysql_select_db($database,$connection)
or die ("Couldn't select database");
$query = "UPDATE items SET '$category' = '$updatevalue' WHERE id = '$id'";
$result = mysql_query($query)
or die ("Couldn't execute query.");