Forum Moderators: coopster
This is my function.
function purchase()
{
global $ucrow, $username, $type, $resell, $name, $damage, $wtype, $link, $name, $cost, $type, $damage, $resell, $wtype;
##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', '$damage', '$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
}
index();
}
This is the form that triggers the function.
. '<form action="weapons.php?action=purchase" method="post">'
. '<input type="hidden" name="name" value="'.$wrow['name'].'" />'
. '<input type="hidden" name="cost" value="'.$wrow['price'].'" />'
. '<input type="hidden" name="type" value="weapon" />'
. '<input type="hidden" name="damage" value="'.$wrow['damage'].'" />'
. '<input type="hidden" name="resell" value="'.$wrow['resell'].'" />'
. '<input type="hidden" name="wtype" value="'.$wrow['type'].'" />'
. '<input type="submit" name="purchase" value="Purchase"/>'
If anyone can help me figure this out.