chriscloyd Posted May 30, 2007 Share Posted May 30, 2007 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'; }*/ } } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/53508-solved-php-help-with-greater-than-and-less-than/ Share on other sites More sharing options...
gabeg Posted May 30, 2007 Share Posted May 30, 2007 - $numallowed is never set to anything from what I can see. - why is the current number of turns passed by POST? This is easy to bypass Quote Link to comment https://forums.phpfreaks.com/topic/53508-solved-php-help-with-greater-than-and-less-than/#findComment-264480 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.