neex1233 Posted June 22, 2009 Share Posted June 22, 2009 This script has one problem, and I have one question. It works, like if you have 4 tokens it doesn't let you buy the item, but when you have enough to buy it, it lets you, but doesn't take the tokens out of the user's account! Can somebody help me? Now my question is how could I add what the user buys to a different table? Thank you. ??? <? ini_set ("display_errors", "1"); error_reporting(E_ALL); require '/home/username/public_html/folder/config.php'; $username = mysql_real_escape_string($_SESSION['username']); $price = 5; $sql="SELECT * FROM users WHERE username='$username'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); if($rows['tokens'] >= $price){ // Check if user has enough tokens $sql = "UPDATE users SET tokens=(tokens-$price) WHERE username='$username'"; mysql_query($sql); echo "Thank you for buying $price!"; }else{ echo "Not enough Tokens"; } ?> Link to comment https://forums.phpfreaks.com/topic/163237-problem-with-subtraction-script/ Share on other sites More sharing options...
rhodesa Posted June 22, 2009 Share Posted June 22, 2009 whenever you do a mysql_query() you should check for an error...on both of your queries in your code put: mysql_query($sql) or die(mysql_error()); and see if mysql reports any problems also, if there aren't any problems, echo the value of $sql for the UPDATE code and make sure all the variables are being inserted properly Link to comment https://forums.phpfreaks.com/topic/163237-problem-with-subtraction-script/#findComment-861247 Share on other sites More sharing options...
neex1233 Posted June 22, 2009 Author Share Posted June 22, 2009 Thanks, I fixed it!!! Link to comment https://forums.phpfreaks.com/topic/163237-problem-with-subtraction-script/#findComment-861264 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.