Forum Moderators: coopster

Message Too Old, No Replies

Simplifying a function

         

dkin

10:26 pm on Jan 12, 2005 (gmt 0)

10+ Year Member



I have a function that is triggered when a user tries to purchase an item. If they have enough it is inserted into the database, if they dont have enough money it says you dont have enough money. But its not working right now that I have placed it into a function. they can buy ok but if they do not have enough gold it does nothing.

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.

ergophobe

12:34 am on Jan 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you have error_reporting set to E_ALL?

Did you output your post array with

print_r($_POST);

dkin

1:10 am on Jan 13, 2005 (gmt 0)

10+ Year Member



error reporting is set to E All.

But still I get nothing, the if else statement doesnt even seem to be triggered.

I will investigate more but if someone could help me out it would probably save me mucho time :).

Cheers

dkin

1:17 am on Jan 13, 2005 (gmt 0)

10+ Year Member



nvm, I figured it out. Sorry I was worried so I rushed to the forum, this post can be deleted if you want lol.

Thanks.

ergophobe

4:29 am on Jan 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Delete the post? We don't let you off that easy ;-) Turn every thread into something useful

- how did you figure out the problem?
- how did you go about fixing it?