Mysqli Not Updating [Resolved]

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Mysqli Not Updating [Resolved]

Post by Epiales »

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:

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/////////////////////////////////////////////////
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 :x :x
Last edited by Epiales on Fri Oct 18, 2013 5:00 pm, edited 1 time in total.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
alexander19
Posts: 180
Joined: Fri Apr 02, 2010 1:05 pm

Re: Mysqli Not Updating

Post by alexander19 »

Change

Code: Select all

 $update_gold = "UPDATE stats SET gold='$gold1' AND food='$food1' WHERE $id = '$_SESSION[userid]";
to

Code: Select all

$update_gold = "UPDATE stats SET gold='$gold1',food='$food1' WHERE $id = '$_SESSION[userid]'";
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Mysqli Not Updating

Post by Epiales »

alexander19 wrote:Change

Code: Select all

 $update_gold = "UPDATE stats SET gold='$gold1' AND food='$food1' WHERE $id = '$_SESSION[userid]";
to

Code: Select all

$update_gold = "UPDATE stats SET gold='$gold1',food='$food1' WHERE $id = '$_SESSION[userid]'";
ROFL! Thanks m8! :oops: :oops: :oops:

What happens when u're twitterpated in code for a long time :mrgreen: :mrgreen:

Thx again. :)
Nothing fancy, but a work in progress!

http://gameplaytoday.net
Post Reply

Return to “Beginner Help and Support”