Mysqli Not Updating [Resolved]
Posted: Fri Oct 18, 2013 4:49 pm
I have rewritten this code over and over and over so many way, but cannot find out why the code is not deducting the gold and food when they purchase a bus... Any help would be awesome. Thanks:
If they don't have enough Gold, it shows the error. If they don't have enough food, it shows the error. If they have both, it goes through and the timer starts.. but it won't deduct the gold and food cost

Code: Select all
<?php
if(isset($_POST['bus'])) {
$sql = "SELECT * from bususerbdlg";
$user_query = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($user_query);
if ($stats_gold < 1000) {
?><div id="error"><?php
echo "<span id='errormess'><big><left><font color='red'>You do not have enough Gold</center></span></big></font>"; ?>
</div>
<meta http-equiv="refresh" content="3;url=cabs.php">
<?php exit;
}
if ($stats_food < 300) {
?><div id="error"><?php
echo "<span id='errormess'><big><left><font color='red'>You do not have enough Food</center></span></big></font>"; ?>
</div>
<meta http-equiv="refresh" content="3;url=cabs.php">
<?php exit;
}
if ($stats_gold >= 1000 || $stats_food >= 300){
$gold1 = ($stats_gold - 1000);
$food1 = ($stats_food - 300);
$update_gold = "UPDATE stats SET gold='$gold1' AND food='$food1' WHERE $id = '$_SESSION[userid]";
$query = mysqli_query($db_conx, $update_gold);
$time = time();
$finish = time() + strtotime($row['times']) + (15 * 1);
$randid = rand(999,9999999);
$bdlgid = 1;
$sql = "UPDATE bususerbdlg SET times1='$currenttime'";
$query = mysqli_query($db_conx, $sql);
$sql = "INSERT INTO bususerbdlg (bdlgid, playerid, times1, finish, randid) VALUES ('$bdlgid','$_SESSION[userid]','$time', '$finish', '$randid')";
$query = mysqli_query($db_conx, $sql);
}}
?>
<?php
$sql = "SELECT * from bususerbdlg";
$user_query = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($user_query);
while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {
if ($row['times1'] >= $row['finish']) {
?> <?php
$bus="<img src='images/bus.png'>";
echo " $bus";
}else{
?> <?php
echo buildtimes($row['finish'] - $row['times1']);
}
}
/////////////////////////////////////////END OF PURCHASING A BUS/////////////////////////////////////////////////

