smithmr8 Posted February 17, 2008 Share Posted February 17, 2008 Hi, The following code doesn't seem to work. The first part, 'sday' works, however the 'bday' does not. <?php if($_GET['step'] == 'sday') { if ($x['money'] >= 250) { mysql_query("UPDATE users SET sdays = sdays+1 WHERE ID = $x[iD]"); mysql_query("UPDATE users SET money = money-250 WHERE ID = $x[iD]"); echo "You bought a Shareholder Day for £250."; } else { echo "You do not have enough money to buy one of these. Try working some more, bum."; } } if($_GET['step'] == 'bday') { if ($x['sdays'] > 0) { mysql_query("UPDATE users SET sdays = sdays-1 WHERE ID = $x[iD]"); mysql_query("UPDATE users SET money = money+175 WHERE ID = $x[iD]"); echo "You sold a Shareholder Day for £175."; } else { echo "You do not have any Shareholder Days to sell. We aint no fools."; } } ?> sdays = table field The first part works perfectly. If the person has the money, then the updates take place. Else, it jumps to the else clause. The second part however, seems to be jumping directly to the else clause, or something else is wrong. Link to comment https://forums.phpfreaks.com/topic/91547-code-not-working-mysql/ Share on other sites More sharing options...
smithmr8 Posted February 17, 2008 Author Share Posted February 17, 2008 OH, and the $x is all fine. It corresponds to this code in the header file. $user = $_SESSION['myusername']; $info="SELECT * FROM users WHERE username='$user'"; $result_info = mysql_query($info); $x=mysql_fetch_array($result_info); Link to comment https://forums.phpfreaks.com/topic/91547-code-not-working-mysql/#findComment-468932 Share on other sites More sharing options...
Barand Posted February 17, 2008 Share Posted February 17, 2008 try echo $x['sdays']; and check the value Link to comment https://forums.phpfreaks.com/topic/91547-code-not-working-mysql/#findComment-469022 Share on other sites More sharing options...
smithmr8 Posted February 17, 2008 Author Share Posted February 17, 2008 Its decided to work now. I'm not sure why it wasn't working before, but all seems well now. Link to comment https://forums.phpfreaks.com/topic/91547-code-not-working-mysql/#findComment-469052 Share on other sites More sharing options...
Barand Posted February 17, 2008 Share Posted February 17, 2008 For future reference, this rule still holds true "If the output isn't what you expected, check the input" Link to comment https://forums.phpfreaks.com/topic/91547-code-not-working-mysql/#findComment-469061 Share on other sites More sharing options...
smithmr8 Posted February 17, 2008 Author Share Posted February 17, 2008 Yeah. Thanks. Link to comment https://forums.phpfreaks.com/topic/91547-code-not-working-mysql/#findComment-469081 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.