Jump to content

PHP/SQL Not showing updated info


lmninfo

Recommended Posts

[labor.php]

The purpose and what I'm attempting to do is when the player

wantes to change their peasants into labors the following

script runs .. Then the form information gets placed into

my peasant2labor.php script (see below for script) and at

the end the the script shows the new number of labors

that have been converted from peasants ..

 

However, this isn't the case .. the old information from

the database is still being used until the player

refreshes THEN the correct numbers are shown ..

 

What am I not doing right?

 

<?php
include 'connect.php';
session_start();
?>


<?php
if (isset($_SESSION['player'])) 
  {
    $player=$_SESSION['player'];
    $userstats="SELECT * from km_users where playername='$player'";
    $userstats2=mysql_query($userstats) or die("Could not get user stats");
    $userstats3=mysql_fetch_array($userstats2);
     
if($userstats3[peasants]<5)
       {
          print "You cannot train labor at this time. <A href='index.php'>Go back to main</a>.";
       }
       else if($userstats3[food]<5)
       {
          print "You cannot build tents at this time. <A href='index.php'>Go back to main</a>.";
       }
       else if($userstats3[peasants]>5)
       {
          

  print "Train Labor <br>";
print "<br>";
print "Base output: <br>";
print "Manpower: +2<br>";
print "Research: +1<br>";
print "<br>";
print "Costs Each:<br>";
print "Food: -5";
print "Peasants -1";

   print "<form action='peasant2labor.php?ID=$user3stats[iD]' method='post'>";
      print "<input type='text' name='scipts' size='6'><br>";
      print "<input type='submit' name='submit' value='submit'></form>";
      print "</td></tr></table>";
      print "</td>";
}
}

 

[peasant2labor.php]

 

<?php
include 'connect.php';
session_start();
?>

<?php
if (isset($_SESSION['player'])) 
  {
    $player=$_SESSION['player'];
    $userstats="SELECT * from km_users where playername='$player'";
    $userstats2=mysql_query($userstats) or die("Could not get user stats");
    $userstats3=mysql_fetch_array($userstats2);
    if(isset($_POST['submit']))
    {
         
        $scipts=$_POST['scipts'];
        $scipts=strip_tags($scipts);
        $maxfood=$scipts*5;
        
        print "<table class='maintable'>";
        print "<tr class='headline'><td><center>Train Labor</center></td></tr>";
        print "<tr class='mainrow'><td>";
        if($userstats3[food]<5)
       {
          print "You cannot train labor at this time. <A href='index.php'>Go back to main</a>.";
       }
       else if($userstats3[peasants]<1)
       {
          print "You cannot train labor at this time. <A href='index.php'>Go back to main</a>.";
       }
       else if($userstats3[food]>=5)
       {
            $updatestats="update km_users set labor=labor+'$scipts', peasants=peasants-'$scipts', food=food-$maxfood where ID='$userstats3[iD]'";
            mysql_query($updatestats) or die("Could not update stats");
            print "Trained Labor";
print "<br>";
print "Labor: $userstats3[labor] ( + $scipts )";
print "<br>";
print "Food: $userstats3[food]";
print "<br>";
print "Peasants: $userstats3[peasants] ( - $scipts ) ";
print "<br>";
print "<tr class='mainrow'><td><A href='index.php'>Back</a></td></tr>";  


        }
        print "</td></tr></table>";



    }
  }
else
  {
    print "Sorry, not logged in  please <A href='login.php'>Login</a><br>";
  
  }

?>


Link to comment
https://forums.phpfreaks.com/topic/154492-phpsql-not-showing-updated-info/
Share on other sites

took me a while to figure out what everything is doing.

 

I think I know your problem.

 

At the end of peasant2labor.php after the update you're simply telling it to print out the following

 

print "<br>";
print "Labor: $userstats3[labor] ( + $scipts )";
print "<br>";
print "Food: $userstats3[food]";
print "<br>";
print "Peasants: $userstats3[peasants] ( - $scipts ) ";
print "<br>";
print "<tr class='mainrow'><td><A href='index.php'>Back</a></td></tr>"; 

 

However, those variables are still filled with the old values from the "select" query you did at the beginning of the file.

 

After the the update you need to perform a new select query to fill those variables with the new values.

 

comprende?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.