apw Posted October 17, 2008 Share Posted October 17, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/128870-php-help-updating-database-problems/ Share on other sites More sharing options...
Maq Posted October 17, 2008 Share Posted October 17, 2008 You're not executing the query, do this: $updatestats="update km_users set peasants=peasants-'$lesspeasant', playerturns=playerturns-1 where ID='$userstats3[iD]'"; mysql_query($updatestats); Quote Link to comment https://forums.phpfreaks.com/topic/128870-php-help-updating-database-problems/#findComment-668105 Share on other sites More sharing options...
apw Posted October 17, 2008 Author Share Posted October 17, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/128870-php-help-updating-database-problems/#findComment-668113 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.