Jump to content

Recommended Posts

Alright heres my problem.  I'm making a web based game that requires turns to play.  Theres an option where people can cash out.  The code belows tries to stop if the user uses more turns then they have.  Each user starts out with 100 turns.  heres my code can anyone help me.  Its not stopping if i use over 100 turns

 

<?php
//cash
echo 'Use some of your turns to produce more resources and to make your population grow.  The more food you have the more people you attract to your territory.<br /><br />';
?>
<form action="index.php?page=cash" method="post">
<table width="100%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td width="14%">Turns</td>
<td width="86%"><label>
<input name="turns" type="text" id="turns" size="2">
</label></td>
</tr>
<tr>
<td> </td>
<td><label>
<input type="submit" name="Submit" value="Cash Out!">
</label></td>
</tr>
</table>
</form>
  <?php
if(isset($_POST['turns'])) {
$turns = $_POST['turns'];
$check_turns = mysql_query("SELECT * FROM other WHERE userid = '".$_SESSION['firefightid']."'");
if ($check_turns) {
	$numallowed = mysql_fetch_array($check_turns);
	if ($turns > $numallowed) {
		$random_turn = rand(1,$numallowed['turns']);
		echo 'You do not have that many turns to cash out with. Try a lower number.  Lets say '.$random_turn.', but thats just what I think.';
	} else {
		$i = 0;
		while ($i < $turns) {
			/*//quires
			$get_other = mysql_query("SELECT * FROM other WHERE userid = '".$_SESSION['firefightid']."'");
			$get_resources = mysql_query("SELECT * FROM resources WHERE userid = '".$_SESSION['firefightid']."'");
			$get_units = mysql_query("SELECT * FROM units WHERE userid = '".$_SESSION['firefightid']."'");
			$units = mysql_fetch_array($get_units);
			$resources = mysql_fetch_array($get_resources);
			$other = mysql_fetch_array($get_other);
			//delete turn from mysql table
			$i++;
			$old_turns = $other['turns'];
			$new_turns = $old_turns - 1;
			mysql_query("UPDATE other SET turns = '$new_turns' WHERE userid = '".$_SESSION['firefightid']."'");
			//production time
			//first la (Light Armor)
			//each barracks can hold 50 soldiers
			//so first check to see if soldiers % 50 is lower than baracks
			$total_units = ($units['lightarmor'] + $units['heavyarmor']) % 50;
			if ($total_units <= $units['barracks']) {
				if ($other['prla'] == 100) {
					$prla = 1.0;
				} else {
					$prla = '.'.$other['prla'];
				}
				$rand = rand(3,7);
				$numOfbarracks = (($units['barracks'] * $prla) + (ceil($units['lightarmor']) % 3)) * $rand;
				echo $numOfbarracks.'<br />';
			} else {
				$new_la = 'You dont have enough barracks to produce anymore Light Armor Units';
			}*/
		}
	}
}
}
?>

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.