Forum Moderators: coopster
I have a database called "purchase". In this database is all the items that all characters have purchased, now, they can go into their inventory and equip any item they choose. But what I would like to do is look at the database when they click the button and insert a "1" into the row that was equipped under the column "equipped" but if there is another item which is the same "item_type" and is equipped I would like to insert a 0 under "equipped" in that row.
If I lost you I apologize my head is not with me today but please try to decipher my babbling, I cannot do much until this is figured out.
Thank you
UPDATE purchase SET equipped=0 WHERE user='$user' AND item_type='$item_type';
INSERT INTO purchase (user, item_type, equipped) VALUES('$user', '$item_type', 1);
I hope this helps.
$purresult = mysql_query("SELECT * FROM purchased where item_name = '$item' and username = '$username'", $link) or die ("query 1: " . mysql_error());
$purrow = mysql_fetch_array($purresult) or die ("query 2: " . mysql_error());
if ($purchasedresult == "TRUE")
{
echo 'EQUIPPED';
}
else
{
echo 'NOT EQUIPPED<br>'.$purrow[item_name].'<br>'.$item.'<br>'.$purrow[username].'<br>'.$username;
}
Thats my code, I the output I am getting is
NOT EQUIPPED
item
item
user
user
the 2 items match and the usernames match, this is why I am baffled.
I hope this helps.
now I am curious.
I am defining my database cells like this
$prow[item_name]
and this is the error I get for it.
Notice: Use of undefined constant item_name - assumed 'item_name' in /home/eqoagui/public_html/game/purchased.php on line 121
How can I output the database without getting these errors?
If a user has a weapon equipped I want the weapon to have a 1 under the equipped column. Now if he buys another weapon and equips it I want to insert a 1 under the equipped column of the new weapon and change the old weapons equipped column back to 0.
Does this make sense?
this will set the okd item to 0
UPDATE purchase SET equipped=0 WHERE user='$user' AND item_type='$item_type';
this inserts the new row for the new item
INSERT INTO purchase (user, item_type, equipped) VALUES('$user', '$item_type', 1);
if the item already exists for that user then you just need to use an update query like the first except setting the new item to 1.
your notice is because of the test if ($equip). I know this is common to use for variable existence but it is a pet peeve of mine. If you want to test if a variable exists then use the function.
if (isset($equip))
UPDATE purchase SET equipped=0 WHERE user='$user';
The INSERT query would remain the same, and of course, do the UPDATE before the INSERT.
I hope this helps.