Forum Moderators: coopster

Message Too Old, No Replies

updating all rows instead of specified.

         

dkin

6:21 am on Jan 6, 2005 (gmt 0)

10+ Year Member



update statement updating every row instead of just the one in the where clause.

Here is my code

##If Weapon Cost is Less then Users Gold Purchase OK
if ($_POST['cost'] <= $ucrow['gold'])
{

$gold = $ucrow['gold'] - $_POST['cost'];

$wiresult = mysql_query("INSERT INTO purchased (username, item_type, resell, item_name, damage, type) VALUES ('$username', '$type', '$resell', '$name', '$defense', '$wtype')", $link);

##If Insert is successful return TRUE
if ($wiresult == TRUE)
{

$ucupdate = mysql_query("UPDATE user_char SET gold = '$gold' where username = '$username'", $link);

echo 'Purchase Successful you have '.$gold.' gold remaining.<br><br>';
}
##Else Purchase Failed
else
{
echo 'You do not have enough gold to purchase this item.<br><br>';
}
##End first if statement
}

##Else Negative
else
{
echo 'You do not have enough gold to purchase this item.<br><br>';
}

}

dreamcatcher

9:11 am on Jan 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would echo your SQL statement to see exactly what values your variables are holding. This should give you a rough idea why all your rows are being updated instead of the ones intended.

dc