Ambuu Posted August 6, 2008 Share Posted August 6, 2008 Alright, So I am making a strategy game in php, and I haven't been able to get past this one part. Here is the main form used for attacking: echo "<form method='POST' action='do_battle.php'>"; echo "<b>Turns</b> (1 - 10): <input type='text' size='3' name='fld_turns'>"; echo "<input type='hidden' name='attackid' value='" . $userid . "'>"; In this form, you input a number of turns (1-10) and attack the person. And here is the part that I'm stuck on at the moment: $sql = "SELECT stats_turns, stats_attack, stats_gold, stats_population FROM stats WHERE stats.id='$attacker"; $result = mysql_query($sql); $stats1 = mysql_fetch_assoc($result); $turns = $stats1['stats_turns']; settype($turns, "int"); settype($fld_turns, "int"); if ($fld_turns <= 0 OR $fld_turns > 10) { $output = "You need to attack with between one and ten turns."; include("./inc/header.inc"); }else{ if ($fld_turns > $turns) { $output = "You don't have enough turns to attack."; include("./inc/header.inc"); } The main problem is taking the fld_turns value (from the battle.php form) and putting it into a positive integer. For some reason, everytime I put a number into the form (I've gone from 1 to over 100), the value of fld_turns is always 0. Any ideas? Link to comment https://forums.phpfreaks.com/topic/118461-solved-need-help/ Share on other sites More sharing options...
DarkWater Posted August 6, 2008 Share Posted August 6, 2008 Where do you actually set $fld_turns...? Link to comment https://forums.phpfreaks.com/topic/118461-solved-need-help/#findComment-609797 Share on other sites More sharing options...
0siris Posted August 6, 2008 Share Posted August 6, 2008 should it not be $_POST[fld_turns]? Link to comment https://forums.phpfreaks.com/topic/118461-solved-need-help/#findComment-609799 Share on other sites More sharing options...
Ambuu Posted August 6, 2008 Author Share Posted August 6, 2008 should it not be $_POST[fld_turns]? I forgot to add this. When I added that, the result became "You don't have enough turns to attack." Link to comment https://forums.phpfreaks.com/topic/118461-solved-need-help/#findComment-609801 Share on other sites More sharing options...
DarkWater Posted August 6, 2008 Share Posted August 6, 2008 What's with the settype() call? PHP is a loosely typed language, so types are relatively insignificant, like say...C where you'd have something like: #include <stdio.h> int main(int argc, char** argv) { int fld_turns, turns; //etc etc } That's unnecessary in PHP. Link to comment https://forums.phpfreaks.com/topic/118461-solved-need-help/#findComment-609804 Share on other sites More sharing options...
0siris Posted August 6, 2008 Share Posted August 6, 2008 what happens if you just echo $_POST[fld_turns]? Also how come you've set the input box for this to size 3, but if the value is 1 - 10 then it would only ever be 2? (I can't see that affecting anything, I'm just pinickity like that ) Link to comment https://forums.phpfreaks.com/topic/118461-solved-need-help/#findComment-609807 Share on other sites More sharing options...
Ambuu Posted August 6, 2008 Author Share Posted August 6, 2008 what happens if you just echo $_POST[fld_turns]? Also how come you've set the input box for this to size 3, but if the value is 1 - 10 then it would only ever be 2? (I can't see that affecting anything, I'm just pinickity like that ) First off, I tried the echo part, and it came up as 10 (when I put ten in). So I just changed: if ($fld_turns <= 0 OR $fld_turns > 10) into: if ($_POST[fld_turns] <= 0 OR $_POST[fld_turns] > 10) And that worked Secondly, I just used 3 because it changed the size of the text box. Size 2 for the text box was too small. And besides, I can still input more than 10. Problem solved, thank you! Link to comment https://forums.phpfreaks.com/topic/118461-solved-need-help/#findComment-609812 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.