Jump to content

Recommended Posts

Hello,

 

I'm trying to work code for my game.  The oject for the code is for the player to change their peasants, which at the start of the game, receive 100, along with 0 labor, 1,000 units of food and 50 turns.

 

The code below is for the form to allow players to change their peasants to labor:

 

<?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>";
  }

  ?>

 

The code below is suppose to process the form from ajobs.php and make changes to the database!

 

<?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 pfile 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);
       print "<center>";
        print "<table class='maintable'>";
        print "<tr class='headline'><td><center>Change  Peasants</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>");
        }     
           
  $updatestats="update km_users set peasants=peasants-'$lesspeasant', playerturns=playerturns-1 where ID='$userstats3[iD]'";
          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>";
  
  }

?>

 

However, I'm not doing something right because the peasants to labor numbers aren't being changed when the player changes the numbers, such as ..

 

If playerA wants to change 10 peasants to labor, the database isn't being changed and that I also need manpower, which also needs to be changed when PlayerA has labors.  Each labor gives PlayerA 2pts of manpower (so if playerA has 10 labor, then PlayerA should have 20 manpower.

 

Thanks for your help! 

Link to comment
https://forums.phpfreaks.com/topic/128870-php-help-updating-database-problems/
Share on other sites

My apologies for the copy and paste with the provided source, the mouse didnt copy that portion and didnt catch the mistake when i read over the post.  As for the question, did i do the correct format for the change from peasants to labor, take the turn away from the player and had the right math figure for manpower when each labor is worth 2points of manpower?

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.