I have table with several fields named item1, item2, item3, etc...
Each field is an int(11) that contains the number of items the person owns.
I want to update one field by adding 1 to it. This usally isn't a problem you just set item1=item1+1 and it works. However, this query is performed after an item is selected in a previous form and the number value is asigned to a variable ($num), so the field names are item$num, item$num, etc...
This works great when doing a select to get info from the field and display how many you have. Say the person wants to know how many apples they have. In another table with full descriptions of the items, apples is set to item2, the varaible $num=2 and the ("select item$num from table where user_name=myname") all works ok.
But doing an update with this variable doesn't work (set item$num=item$num+1)
Here is the actual code:
$itemadd = ( "update items set item$num=item$num+1 where user_name='{$session["name"]}'" );
$itemupdate = mysql_query($itemadd) or die(db_error());
echo "Added 1 more item to your inventory";
I get no errors returned and the echo statement is executed.
Any reason why it won't work like this?
Thanks