Jump to content

SQL Query


apw

Recommended Posts

Hello

 

  I'm working on a script that handles the form add, subtracts and even multiplies the variables and queries the SQL.

 

When player registers, the player receives the following:

* 100 peasants

* 0 labor

* 0 manpower

 

The script changes the players number of peasants to labor .. when player changes the labor amount, the player

also receives 2-points per labor receives:

 

Please check over the script, the peasants, labor and manpower isn't changing...

 



ajobs.php (form action handle)
<?php

if ($userstats3[peasants]<=0)
{
print "Not enough peasants";
  }
  else
  {
  print "You have $userstats3[peasants] peasants available!<br>";
  print "<form action='ajob.php' method='post'>";
      print "<input type='text' name='lesspeasant' size='5'><br>";
      print "<input type='submit' name='submit' value='Change'></form>";
  }
 
  ?>
[/code]

 

from ajob.php (handles the query with math)

 

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

<link rel="stylesheet" href="style.css" type="text/css">
<?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']))
    {
         
       $lesspeasant=$_POST['lesspeasant'];
       $lesspeasant=strip_tags($lesspeasant);
       $lesslaboe=$_POST['lesslabor'];
       $lesslabor=strip_tags($lesslabor);

       print "<center>";
        print "<table class='maintable'>";
        print "<tr class='headline'><td><center>Buy Science</center></td></tr>";
        print "<tr class='mainrow'><td>";
        if($peasant<0)
        {
           print "You cannot change, not enough peasants!. Back to <A href='index.php'>Main</a>";
        }
        else if($userstats3[playerturns]<1)
        {
           die("You must have at least 1 turn to Change. Go back to <A href='index.php'>Main</a>");
        }     
           $lesspeasants=$userstats3[peasants];
           $lesspeasant=$userstats3[peasants]-$lesspeasant;
           $lesslabor=$lesspeasant;
           $userstats3[labor]=$lesspeasant;
           $userstats3[labor]*2;
           
  $updatestats="update km_users set peasants=peasants-'$lesspeasant', playerturns=playerturns-1 where ID='$userstats3[iD]'";
         mysql_query($updatestats) or die("Could not update stats");
print "You Changed $lesspeasant peasants to labor and have $manpower manpower and $userstats3[labor] laborers! Back to <A href='index.php'>Main Page</a>";

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

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.