I have a piece of code, where every 20 mins, a system task runs a SQL query, adding to one of my database tables (tickets). I have if if statement thats supposed to find than number (tickets) and use it to allow someone to "buy" items from my store. It allows the user to buy more items, than they have tickets for (bringing their balance in to the negatives) like its just completely skipping my else statement. Is there something im doing wrong?
also thought i would add, the "tickets" column is INT and not like, VARCHAR or anything
the thing is also, it worked perfectly a few hours ago, so im not sure if i added something by accident, but now its not working
Be watching, the problem here is "if ($rewards > 4)"
<div class="box">
<div class="contentHeader headerGreen">
<div class="inside">
5 Tickets
</div>
</div>
<ul>
<img src="/swf/c_images/album1584/2015HA.gif" align="right">
<li>25k Credits</li>
<li>25k Pixels</li>
<li>5 Diamonds
</ul>
<?php
if(isset($_POST['buy1'])) {
$getRewards = mysql_query("SELECT tickets FROM users WHERE id = '" . $_SESSION['user']['id'] . "'");
while($rewards = mysql_fetch_assoc($getRewards)) {
if($rewards > 4) {
mysql_query("UPDATE users SET tickets = tickets-5 WHERE id = '" . $_SESSION['user']['id'] . "'") or die(mysql_error());
mysql_query("UPDATE users SET credits = credits+25000 WHERE id = '" . $_SESSION['user']['id'] . "'");
mysql_query("UPDATE users SET activity_points = activity_points+25000 WHERE id = '" . $_SESSION['user']['id'] . "'");
mysql_query("UPDATE users SET vip_points = vip_points+5 WHERE id = '" . $_SESSION['user']['id'] . "'");
echo '
<div class="alert alert-sucess">
<strong>Well Done!</strong> Your items have been added.
</div>';
}
else if($rewards < 5) {
echo '
<div class="alert alert-error">
<strong>Error:</strong> You Do NOT Have Enough Tickets To Buy This
</div>';
}
/*else {
echo '
<div class="alert alert-error">
<strong>Error:</strong> You Do NOT Have Enough Tickets To Buy This
</div>';
}*/
}
}
?>
<form method='post'>
<input type="submit" value="Buy" name="buy1" style="width: 138px;cursor: pointer;" />
</form>
</div>