DEVILofDARKNESS Posted April 25, 2009 Share Posted April 25, 2009 Hi, none of my $_POST[''] is past through to the code, =-(; only the <input type='submit'> works, but the radio buttons somehow, don't, and I have used them the same way as somewhere else where they do work. , can someone explain me why it won't work? <?php session_start(); require_once ''; //left away for security reasons $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); $page = (int)$_GET['page']; $username = $_SESSION['username']; $yourownnation = $_SESSION['nationid']; $query = "SELECT user_id FROM users WHERE user_name = '$username'"; $result = mysql_query($query) or die(mysql_error()."<br>".$query); list($id) = mysql_fetch_row($result); if(isset($_POST['submit1'])) { $name = $_POST['Name']; $capital = $_POST['capital']; $religion = $_POST['religion']; $government = $_POST['government']; $query = "SELECT COUNT(nation_id) FROM nations"; $result = mysql_query($query) or die(mysql_error()."<br>".$query); list($nationid) = mysql_fetch_row($result); $nationid += 1; $query = "INSERT INTO nations(nation_id,nation_name,nation_ruler_id,nation_capital,nation_religion,nation_government,nation_money) VALUES ('$nationid','$name','$id','$capital','$religion','$government','500')"; $result = mysql_query($query) or die(mysql_error()."<br>".$query); header('location:/createnation.php?page=2'); }elseif(isset($_POST['submit2'])) { $regchk = $_POST['region']; $query = "SELECT region_price FROM regions WHERE region_name = '$regchk'"; $result = mysql_query($query) or die(mysql_error()."<br>".$query); list($chkregprice) = mysql_fetch_row($result); if($chkregprice > 500) { echo "Sorry You don't have enough money (You have €500)"; }elseif($chkregprice <= 500) { $query = "UPDATE regions SET region_ruler_id = '$id' WHERE region_name='$regchk'"; $result = mysql_query($query) or die(mysql_error()."<br>".$query); $newmoney = 500 - $chkregprice; $query = "UPDATE nations SET nation_money = '$newmoney' WHERE nation_ruler_id = '$id'"; $result = mysql_query($query) or die(mysql_error()."<br>".$query); $query = "UPDATE nations SET SRRL = '$regchk' WHERE nation_ruler_id = '$id'"; $result = mysql_query($query) or die(mysql_error()."<br>".$query); $query = "INSERT INTO army(nation_id) VALUES ('$yourownnation')"; $result = mysql_query($query); echo "You have enough Money!,<br> The region is now yours.<br> You have now €{$newmoney} left<p>"; header('location:/createnation.php?page=3'); } } ?> <html> <head> <title> EUROPIA! -- Create A Nation! </title> <meta name="author" content="Kruptein"> <link rel="shortcut icon" href="/images/favicon.ico"> </head> <body> <table border="1" width="100%" height="100%"> <tr> <td colspan = "3" height="15%"> <b><u><center>EUROPIA! -- Create A Nation</center></u></b> </td> </tr> <tr> <td width="10%"> <iframe src="/navigation/loggedin.php" frameborder="0" width="100%" scrolling="no" height="100%"></iframe> </td> <td height="80%" width="90%"> <center> <?php if($page == 1) { echo '<b>Welcome,' . $username . '</b><br> It\'s now up to you to create your own empire and conquer the whole world!<p> But first we have to get some information about your new nation.<br> STEP ONE:<p> <form action="" method="post"> <table border="0"> <tr><td>Nation Name: </td><td><input type="text" name="Name"></td><td></td></tr> <tr><td>The Capital Name of Your Nation: </td><td><input type="text" name="capital"></td><td></td></tr> <tr><td>Your Primary Religion*: </td><td><select name="religion"><option value="Buddhism">Buddishm</option><option value="Christianity">Christianity</option><option value="islam">Islam</option><option value="nonreligious">Non Religious</option><option value="Hinduism">Hinduism</option></select></td><td><a href="http://www.orionsarm.com/civ/government.html" target="_blank"><i>What are the differences?</i></a></td></tr> <tr><td>Government Type: </td><td><select name="government"><option value="Democracy">Democracy</option><option value="Republic">Republic</option><option value="Dictatorship">DictatorShip</option><option value="Monarchy">Monarchy</option><option value="Plutocracy">Plutocracy</option><option value="Stratocracy">Stratocracy</option><option value="Theocracy">Theocracy</option></select></td><td><a href="http://www.adherents.com/Religions_By_Adherents.html" target="_blank"><i>What are the differences?</i></a></td></tr> <tr><td colspan = "3"><i>*You can create an own religion if you have more money</i></td></tr> <tr><td><input type="submit" name="submit1" value="Create!"></td><td>--</td><td<input type="reset"></td></tr> </table> </form>'; }elseif($page == 2) { echo 'Now you have created a nation, you also need a region to rule over.<p> STEP TWO:<br> <form action="" method="post"> <table border="0"> <tr><td><u><b>Region Name</b></u></td><td><u><b>Population</b></u></td><td><u><b>Money</b></u></td><td><u><b>Price</b></u></td></tr> <tr>'; $query = "SELECT * FROM regions"; $result = mysql_query($query); while($fields = mysql_fetch_array($result)) { echo '<td>' . $fields['region_name'] . '</td><td>' . $fields['region_population'] . '</td><td>' . $fields['region_outputs'] . '</td><td><b>' . $fields['region_price'] . '</b></td><td><input type="radio" name="region" value="' . $fields['region_name'] . '"></td></tr>'; } echo '<tr><td><input type="submit" name="submit2" value="Buy"> -- <input type="reset"></td></tr> </table> </form>'; }elseif($page == 3) { echo 'Congrulations! You have Completed All Steps,<br> You can now start to play. Log once again in and you are able to play Europia!</p> <a href="/login.php">Login</a>'; }else{ echo 'There was a problem'; }?> </center> </td> </tr> <tr> <td colspan = "3" height="5%"> <center>Made by Kruptein</center> </td> </tr> </table> </body> </html> Quote Link to comment Share on other sites More sharing options...
DjMikeS Posted April 25, 2009 Share Posted April 25, 2009 Have you tried checking what the $_POST array contains ? print_r($_POST); I also believe that you should have a valid form action.... <form action="thispage.php" method="post"> Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted April 25, 2009 Author Share Posted April 25, 2009 O No, I gave the wrong code, :s the real code is: <?php session_start(); require_once 'login-check.php'; require_once "config.php"; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Connection Error: ' . mysql_error()); mysql_select_db($dbname) or die('Select Database Error: ' . mysql_error()); $nationid = $_SESSION['nationid']; $username = $_SESSION['username']; $query = "SELECT user_id FROM users WHERE user_name = '$username'"; $result = mysql_query($query); list($userID) = mysql_fetch_row($result); if ($nationid == $userID) { $navigation = "gov.php?nation_id=" . $nationid; } else { $navigation = "loggedin.php?nation_id=" . $nationid; } $page = $_GET['page']; $query = "SELECT SRRL FROM nations WHERE nation_id = '$nationid'"; $result = mysql_query($query); //SRRL = Standard Region for Rocket Launching list($SRRL) = mysql_fetch_row($result); if ($_POST['one']) { $query = "SELECT region_ruler_id FROM regions WHERE region_id = '$SRRL'"; $result = mysql_query($query); list($srrluser) = mysql_fetch_row($result); if ($ssrluser = $userID) { header('location:/attack.php?page=2'); } else { $text = "Your SRRL isn't a region of you, to set a new SRRL go to government -> change your nation."; $color = "red"; $rockets = "0"; } } elseif ($_POST['two']) { $rua = $_POST['region']; $weaponname = $_POST['rocktype']; $query = "SELECT ammount FROM army WHERE (weapon_name='$weaponname') AND (region_id = '$SRRL')"; $result = mysql_query($query); list($ammount) = mysql_fetch_row($result); header('location:/attack.php?page=3'); }elseif($_POST['three']) { if ($_POST['ammrock'] > $ammount) { $text = $_POST['ammrock'] . " " . $rua . " " . $weaponname . " You don't have enough rockets to do that, You will have to buy, researsh or transport more rockets to your SRRL!!"; $color = "red"; } else { $_SESSION['SRRL'] = $SRRL; $_SESSION['rockets'] = $_POST['ammrock']; //RUA = Region Under Attack $_SESSION['RUA'] = $_POST['region']; header('location:/attacking.php'); } } ?> <html> <head> <title> EUROPIA! </title> <meta name="author" content="Kruptein"> <link rel="shortcut icon" href="/images/favicon.ico"> <link rel="stylesheet" type="text/css" href="/CSS/attack.css"> </head> <body> <table border="1" width="100%" height="100%"> <tr> <td colspan = "3" height="15%"> <b><u><center>EUROPIA!</center></u></b> </td> </tr> <tr> <td width="10%"> <iframe src="/navigation/<?php echo $navigation; ?>" frameborder="0" width="100%" scrolling="no" height="100%"></iframe> </td> <td height="80%" width="90%"> <center> <big><?php echo "<font color='" . $color . "'>" . $text . "</font></big>"; if ($page == 1) { echo '<form action="" method="POST"><table border="0"><tr><td colspan="2"><center><big>Launch a Rocket on:</big></center></td></tr>'; $query = "SELECT * FROM regions WHERE region_ruler_id <> '$userID'"; $result = mysql_query($query); while ($regions = mysql_fetch_array($result)) { echo '<tr><td><b>' . $regions['region_name'] . '</td><td><input type="radio" name="region" value="' . $regions['region_id'] . '"></td></tr>'; } echo '<tr><td colspan="2"><input type="submit" name="one" value="Next"></td></tr></table></form>'; } elseif ($page == 2) { ?> <form action='' method='POST'><table border='0'><tr><td><center><big>Name</big></center></td><td><center><big>In Stock</big></center></td><td><center><big>Choose type</big></center></td></tr> <?php $query = "SELECT weapons.*,army.* FROM weapons INNER JOIN army ON army.weapon_name = weapons.name WHERE (army.region_id = '$SRRL') AND (weapons.type='offensive')"; $result = mysql_query($query); while ($weapons = mysql_fetch_array($result)) { echo '<tr><td>' . $weapons['name'] . '</td><td><center>' . $weapons['ammount'] . '</center></td><td><input type="radio" name="rocktype" value="' . $weapons['name'] . '"></td></tr> <tr><td colspan="3"><input type="submit" name="two" value="Next"></td></tr>'; } ?> </table></form> <?php }elseif($page == 3) { echo '<form action="" method="POST"><table border="0"><tr><td>Ammount of rockets you want to fire: </td><td><input type="text" name="ammrock"></td></tr><tr><td><i>You can fire ' . $ammount . ' rockets</i></td><td><center><input type="submit" name="three" value = "Launch"></center></td></tr></table></form>'; } ?> </center> </td> </tr> </table> </body> </html> Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted April 25, 2009 Author Share Posted April 25, 2009 And what is wrong with <form action="">, it always worked until now,! Quote Link to comment Share on other sites More sharing options...
trq Posted April 25, 2009 Share Posted April 25, 2009 Again, Have you tried checking what the $_POST array contains ? Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted April 25, 2009 Author Share Posted April 25, 2009 Yes, It don't contain anything That's the problem, I dunno why it doesn't contain anything Quote Link to comment Share on other sites More sharing options...
DjMikeS Posted April 25, 2009 Share Posted April 25, 2009 Does your script even pickup on a submitted form ? Just put an: echo "test"; or something right after if ($_POST['one']) { Also...why are you constantly defining a connection to the database ? Wouldn't it be much easier to put that in a file, say: db.php and include that in your scripts...? Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted April 25, 2009 Author Share Posted April 25, 2009 yes I know, I will do it in the future, that indeed saves a lil time., but back to topic, Yes it does, because if I click on the submit button on ($page == 1) {...} I can see the content of ($page == 2 {...} and if I submit that one, I see the content of page 3 and if I submit that one, it saids, I don't have enough rockets, and that's because None of the radio buttons gave a value. only the submit buttons and the text box Quote Link to comment Share on other sites More sharing options...
ch1326 Posted April 25, 2009 Share Posted April 25, 2009 Have u tried print_r Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted April 25, 2009 Author Share Posted April 25, 2009 Yes I did, read the previous messages and you can read, That the radio buttons don't give a value to the $_POST. Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted April 25, 2009 Author Share Posted April 25, 2009 Now it's totaly, ***, on an other page I was developping, again with radio buttons, again the buttons don't pass a value! AH, I'm probably just to stupid to even set up a simple script with radio buttons :-(. here's the code from that second page, (it is less queries so I think easier to find the problem) <?php session_start(); require_once 'login-check.php'; require_once ""; //left away for security reasons $conn = mysql_connect ( $dbhost,$dbuser,$dbpass ) or die ( 'Connection Error: ' . mysql_error () ); mysql_select_db ( $dbname ) or die ( 'Select Database Error: ' . mysql_error () ); $nationid = $_SESSION['nationid']; $username = $_SESSION['username']; $query = "SELECT user_id FROM users WHERE user_name = '$username'"; $result = mysql_query($query); list($userID) = mysql_fetch_row($result); if($nationid == $userID) { $navigation = "gov.php?nation_id=" . $nationid; }else{ $navigation = "loggedin.php?nation_id=" . $nationid; } if($_POST['buypromo']) { header('location:/invest.php?type=bp'); }elseif($_POST['promoamm']) { $price = $_POST['promoamm'] * 100; $query = "SELECT nation_money FROM nations WHERE nation_id = '$nationid'"; $result = mysql_query($query); list($nationmoney) = mysql_fetch_row($result); if($nationmoney >= $price) { $nationmoney = $nationmoney - $price; $query = "SELECT SRRL FROM nations WHERE nation_id = '$nationid'"; $result = mysql_query($query); list($SRRL) = mysql_fetch_row($result); //SRRL = Standard Region for Rocket Launching $query = "SELECT attack_rockets FROM army WHERE region_id = '$SRRL'"; $result = mysql_query($query); list($attrockets) = mysql_fetch_row($result); $attrockets = $attrockets + $_POST['promoamm']; $query = "UPDATE nations SET nation_money = '$nationmoney' WHERE nation_id = '$nationid'"; $result = mysql_query($query); $query = "UPDATE army SET attack_rockets = '$attrockets' WHERE region_id = '$SRRL'"; $result = mysql_query($query); echo "You have just bought " . $_POST['promoamm'] . " Attack-Rockets for €" . $price . "!<br>You now have €" . $nationmoney . " over."; }else{ echo "Oh, you don't have enough money.<br>You have €" . $nationmoney . " and you need €" . $price; } }elseif($_POST['SubBuyWeap']) { $weaponid = $_POST['BuyWeapon']; $query = "SELECT offensive_level FROM weapons WHERE id = '$weaponid'"; $result = mysql_query($result); list($offlvlweap) = mysql_fetch_row($result); $query = "SELECT defensive_level FROM weapons WHERE id = '$weaponid'"; $result = mysql_query($result); list($deflvlweap) = mysql_fetch_row($result); $query = "SELECT offensive_level FROM nations WHERE nation_id = '$nationid'"; $result = mysql_query($result); list($offlvl) = mysql_fetch_row($result); $query = "SELECT defensive_level FROM nations WHERE nation_id = '$nationid'"; $result = mysql_query($result); list($deflvl) = mysql_fetch_row($result); if(($offlvl >= $offlvlweap) && ($deflvl >= $deflvlweap)) { header('location:/invest.php?type=bw'); }else{ header('location:/invest.php?type=rnt'); } }elseif($_POST['weaponamm']) { $query = "SELECT price FROM weapons WHERE id = '$weaponid'"; $result = mysql_query($query); list($price) = mysql_fetch_row($result); $query = "SELECT nation_money FROM nations WHERE nation_id = '$nationid'"; $result = mysql_query($query); list($money) = mysql_fetch_row($result); $weaponamm = $_POST['weaponamm']; $moneyneeded = $price * $weaponamm; if($moneyneeded <= $money) { $newmoney = $money - $moneyneeded; $query = "UPDATE nations SET nation_money = '$newmoney' WHERE nation_id='$nationid'"; $result = mysql_query($query); $query = "SELECT SRRL FROM nations WHERE nation_id = '$nationid'"; $result = mysql_query($query); list($SRRL) = mysql_fetch_row($result); $query = "UPDATE army SET ammount = ammount + '$weaponamm' WHERE region_id = '$SRRL'"; $result = mysql_query($query); header('location:/invest.php?type=home'); }else{ echo "You don't have enough money,."; } } ?> <html> <head> <title> EUROPIA! </title> <meta name="author" content="Kruptein"> <link rel="shortcut icon" href="/images/favicon.ico"> <!--<link rel="stylesheet" type="text/css" href="/CSS/attack.css">--> </head> <body> <table border="1" width="100%" height="100%"> <tr> <td colspan = "3" height="15%"> <b><u><center>EUROPIA!</center></u></b> </td> </tr> <tr> <td width="10%"> <iframe src="/navigation/<?php echo $navigation; ?>" frameborder="0" width="100%" scrolling="no" height="100%"></iframe> </td> <td height="80%" width="90%"> <center> <?php $type = $_GET['type']; switch($type) { case "home": echo "<u><b>Welcome In The International Nation Shop (INS)</u></b><br><font size = '-1'>The shop for every Nation in whole the world</font><br><font size = '-2'>Except Russia</font><p> You can Choose between Several Options In This Shop.<br> <a href='/invest.php?type=bnw'>The BNW</a>: Buy new Weapons<br> <a href='/invest.php?type=bnd'>The BND</a>: Buy new Defence<br> <a href='/invest.php?type=uw'>The UW</a>: Upgrade Weapons<br> <a href='/invest.php?type=rnt'>The RNT</a>: Researsh new Technologies<br> <a href='/invest.php?type=bar'>The BAR</a>: Buy A Region<br> Enjoy!"; break; case "bnw": echo "<form action='' method='post'><table border='0' height='100%' width='100%'><tr><td><b><u><center>Welcome In The BNW!</b></u></center></td></tr> <tr><td><center>The Weapon This Month In Promo Is The Attack-Rocket!</center></td></tr> <tr><td><center>Now For Only 100€! <input type='submit' name='buypromo' value='Buy!'></center></td></tr> <tr><td> </td></tr> <tr><td><center>Seek trough the alphabetical list: <a href='/invest.php?type=tal'>Seek!</a></center></td></tr></table></form> "; break; case "tal": echo "<center>Attention! If U buy a weapon from the Alphabetical List, you buy The Full Price!<br>Even if it is in Promo!<br>To buy the promo price you have to go <a href='/invest.php?type=bnw'>Here</a><p>"; echo '<form action="" method="post"><table border="1" height="100%" width="100%"> <tr><td><u><b>Weapon Name</b></u></td><td><b><u>Weapon Type</u></b></td><td><b><u>Off. Level Needed</u></b></td><td><b><u>Def. Level Needed</u></b></td><td><b><u>Price</b></u></td><td>Buy</td></tr>'; $query = "SELECT * FROM weapons"; $result = mysql_query($query); while($weapons = mysql_fetch_array($result)) { echo '<tr><td>' . $weapons['name'] . '</td><td>' . $weapons['type'] . '</td><td>' . $weapons['offensive_level'] . '</td><td>' . $weapons['defensive_level'] . '</td><td>' . $weapons['price'] . '</td><td><input type="radio" value="'.$weapons['id'].'" name="BuyWeapon"></td></tr>'; } echo '<tr><td colspan="6"><center><input type="submit" name="SubBuyWeap" value="Buy"></center></td></tr></table></form>'; break; case "bnd": echo "Sorry But We're Closed"; break; case "uw": echo "Sorry But We're Closed"; break; case "rnt": echo "Sorry But We're Closed"; break; case "bar": echo "Sorry But We're Closed"; break; case "bp": echo "<form action='' method='post'>To buy The Promo Just fill in how many you articles you want to buy. <br><input type='text' name='promoamm'> <input type='submit' value='buy'>"; break; case "bw": echo "<form action='' method='post'>How Many Articles Do you want to buy?<br> <input type='text' name='weaponamm'> <input type='submit' value='Buy'>"; break; default: echo "Our Store Is located <a href='/invest.php?type=home'>Here</a>"; break; } ?> </center> </td> </tr> </table> </body> </html> Quote Link to comment Share on other sites More sharing options...
DjMikeS Posted April 25, 2009 Share Posted April 25, 2009 First off, your code is totally crap... Where is the KISS principle ? Begin by taking out the db connection as I told you before... Next, your queries are wrong.... $query = "SELECT offensive_level FROM weapons WHERE id = '$weaponid'"; $result = mysql_query($result); list($offlvlweap) = mysql_fetch_row($result); $query = "SELECT defensive_level FROM weapons WHERE id = '$weaponid'"; $result = mysql_query($result); Third, try to use unique var names so that you can echo their contents for debugging If you would rewrite the snipped above: $getOfLevel = mysql_query ("SELECT offensive_level FROM weapons WHERE id = '$weaponid'") or die(mysql_error()); $offlvlweap = mysql_fetch_array($getOfLevel); $getDefLevel = mysql_query ("SELECT defensive_level FROM weapons WHERE id = '$weaponid'") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted April 25, 2009 Author Share Posted April 25, 2009 First: What Is The Kiss Principle Second: What is wrong with the query? Third: I'm not a Pro, I'm a beginner, so you can't blame me that my code is crap, so can you say it next time a lil bit more polite, because I really get the feeling I can't do anything at all if you say it is crap Oh, and why are you using fetch_array, because it is only one row from the database? Quote Link to comment Share on other sites More sharing options...
DjMikeS Posted April 25, 2009 Share Posted April 25, 2009 http://en.wikipedia.org/wiki/KISS_principle Keep It Simple, Stupid. What's wrong with the query you ask? Do you have access to your server? Because if that query is not giving you any errors, your level of error reporting is wrong... $query = "SELECT defensive_level FROM weapons WHERE id = '$weaponid'"; $result = mysql_query($result); You don't see anything wrong with that ? Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted April 25, 2009 Author Share Posted April 25, 2009 First: The query is fine! Second: By just changing: $query = "SELECT offensive_level FROM weapons WHERE id = '$weaponid'"; $result = mysql_query($result); list($offlvlweap) = mysql_fetch_row($result); $query = "SELECT defensive_level FROM weapons WHERE id = '$weaponid'"; $result = mysql_query($result); Into This: $getoflvl = mysql_query("SELECT offensive_level FROM weapons WHERE id = '$weaponid'") or die(mysql_error()); $offlvlweap = mysql_fetch_array($result); $getdeflvl = mysql_query("SELECT defensive_level FROM weapons WHERE id = '$weaponid'") or die(mysql_error()); $deflvlweap = mysql_fetch_array($result); $getownofflvl = mysql_query("SELECT offensive_level FROM nations WHERE nation_id = '$nationid'") or die(mysql_error()); $offlvl = mysql_fetch_array($result); $getowndeflvl = mysql_query("SELECT defensive_level FROM nations WHERE nation_id = '$nationid'") or die(mysql_error()); $deflvl = mysql_fetch_array($result); It is solved like you said, but I don't see why, it works now and didn't before? Quote Link to comment Share on other sites More sharing options...
DjMikeS Posted April 25, 2009 Share Posted April 25, 2009 I never use list, but I think that's the problem... http://nl3.php.net/list And this $query = "SELECT offensive_level FROM weapons WHERE id = '$weaponid'"; $result = mysql_query($result); Is NOT fine! Which query is mysql_query supposed to run ? Exactly, none because $result is not set to a query... $query = "SELECT offensive_level FROM weapons WHERE id = '$weaponid'"; $result = mysql_query($query); Would make a whole lot more sense.... Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted April 25, 2009 Author Share Posted April 25, 2009 Ok, but if list isn't nesecary, for what is it good instead? But why do you fetch_array instead of fetch_row? if you do fetch_row you have to do list also ? Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted April 25, 2009 Author Share Posted April 25, 2009 Ok, the Invest page works, but the attack page still doesn't work... <?php session_start(); require_once 'login-check.php'; require_once ""; // database file $nationid = $_SESSION['nationid']; $username = $_SESSION['username']; $query = "SELECT user_id FROM users WHERE user_name = '$username'"; $result = mysql_query($query); list($userID) = mysql_fetch_row($result); $navigation = "gov.php?nation_id=" . $nationid; $page = $_GET['page']; $getSrrl = mysql_query("SELECT SRRL FROM nations WHERE nation_id = '$nationid'") or die(mysql_error()); //SRRL = Standard Region for Rocket Launching list($SRRL) = mysql_fetch_row($getSrrl); if ($_POST['one']) { $getRegionRulerId = mysql_query("SELECT region_ruler_id FROM regions WHERE region_id = '$SRRL'") or die(mysql_error()); list($srrluser) = mysql_fetch_row($getRegionRulerId); if ($ssrluser = $userID) { header('location:/attack.php?page=2'); } else { $text = "Your SRRL isn't a region of you, to set a new SRRL go to government -> change your nation."; $color = "red"; $rockets = "0"; } } elseif ($_POST['two']) { $weaponname = $_POST['rocktype']; header('location:/attack.php?page=3'); }elseif($_POST['three']) { $getAmmount = mysql_query("SELECT ammount FROM army WHERE (weapon_name='$weaponname') AND (region_id = '$SRRL')") or die(mysql_error()); list($ammount) = mysql_fetch_row($getAmmount); if ($_POST['ammrock'] > $ammount) { $text = $ammount . " You don't have enough rockets to do that, You will have to buy, researsh or transport more rockets to your SRRL!!"; $color = "red"; } else { $_SESSION['SRRL'] = $SRRL; $_SESSION['rockets'] = $_POST['ammrock']; //RUA = Region Under Attack $_SESSION['RUA'] = $_POST['region']; header('location:/attacking.php'); } } ?> <html> <head> <title> EUROPIA! </title> <meta name="author" content="Kruptein"> <link rel="shortcut icon" href="/images/favicon.ico"> <link rel="stylesheet" type="text/css" href="/CSS/attack.css"> </head> <body> <table border="1" width="100%" height="100%"> <tr> <td colspan = "3" height="15%"> <b><u><center>EUROPIA!</center></u></b> </td> </tr> <tr> <td width="10%"> <iframe src="/navigation/<?php echo $navigation; ?>" frameborder="0" width="100%" scrolling="no" height="100%"></iframe> </td> <td height="80%" width="90%"> <center><form action='/attack.php' method='POST'> <big><?php echo "<font color='" . $color . "'>" . $text . "</font></big>"; if ($page == 1) { echo '<table border="0"><tr><td colspan="2"><center><big>Launch a Rocket on:</big></center></td></tr>'; $getAll = mysql_query("SELECT * FROM regions WHERE region_ruler_id <> '$userID'") or die(mysql_error()); while ($regions = mysql_fetch_array($getAll)) { echo '<tr><td><b>' . $regions['region_name'] . '</td><td><input type="radio" name="region" value="' . $regions['region_id'] . '"></td></tr>'; } echo '<tr><td colspan="2"><input type="submit" name="one" value="Next"></td></tr></table>'; } elseif ($page == 2) { ?> <table border='0'><tr><td><center><big>Name</big></center></td><td><center><big>In Stock</big></center></td><td><center><big>Choose type</big></center></td></tr> <?php $getAllWeap = mysql_query("SELECT weapons.*,army.* FROM weapons INNER JOIN army ON army.weapon_name = weapons.name WHERE (army.region_id = '$SRRL') AND (weapons.type='offensive')") or die(mysql_error()); while ($weapons = mysql_fetch_array($getAllWeap)) { echo '<tr><td>' . $weapons['name'] . '</td><td><center>' . $weapons['ammount'] . '</center></td><td><input type="radio" name="rocktype" value="' . $weapons['name'] . '"></td></tr> <tr><td colspan="3"><input type="submit" name="two" value="Next"></td></tr>'; } ?> </table> <?php }elseif($page == 3) { echo '<table border="0"><tr><td>Ammount of rockets you want to fire: </td><td><input type="text" name="ammrock"></td></tr><tr><td><i>You can fire ' . $ammount . ' rockets</i></td><td><center><input type="submit" name="three" value = "Launch"></center></td></tr></table>'; } ?> </form></center> </td> </tr> </table> </body> </html> Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted April 29, 2009 Author Share Posted April 29, 2009 Okay, I've tried to find the mistake, but still can't find it Here's the code one's again: <?php session_start(); require_once 'login-check.php'; require_once ""; //database options $nationid = $_SESSION['nationid']; $username = $_SESSION['username']; $query = "SELECT user_id FROM users WHERE user_name = '$username'"; $result = mysql_query($query); list($userID) = mysql_fetch_row($result); $navigation = "gov.php?nation_id=" . $nationid; $page = $_GET['page']; $getSrrl = mysql_query("SELECT SRRL FROM nations WHERE nation_id = '$nationid'") or die(mysql_error()); //SRRL = Standard Region for Rocket Launching list($SRRL) = mysql_fetch_row($getSrrl); if ($_POST['one']) { $getRegionRulerId = mysql_query("SELECT region_ruler_id FROM regions WHERE region_id = '$SRRL'") or die(mysql_error()); list($srrluser) = mysql_fetch_row($getRegionRulerId); if ($ssrluser = $userID) { header('location:/attack.php?page=2'); } else { $text = "Your SRRL isn't a region of you, to set a new SRRL go to government -> change your nation."; $color = "red"; $rockets = "0"; } } elseif ($_POST['two']) { $weaponname = $_POST['rocktype']; header('location:/attack.php?page=3'); }elseif($_POST['three']) { $getAmmount = mysql_query("SELECT ammount FROM army WHERE (weapon_name='$weaponname') AND (region_id = '$SRRL')") or die(mysql_error()); list($ammount) = mysql_fetch_row($getAmmount); if ($_POST['ammrock'] > $ammount) { $text = $ammount . " You don't have enough rockets to do that, You will have to buy, researsh or transport more rockets to your SRRL!!"; $color = "red"; } else { $_SESSION['SRRL'] = $SRRL; $_SESSION['rockets'] = $_POST['ammrock']; //RUA = Region Under Attack $_SESSION['RUA'] = $_POST['region']; header('location:/attacking.php'); } } ?> <html> <head> <title> EUROPIA! </title> <meta name="author" content="Kruptein"> <link rel="shortcut icon" href="/images/favicon.ico"> <link rel="stylesheet" type="text/css" href="/CSS/attack.css"> </head> <body> <table border="1" width="100%" height="100%"> <tr> <td colspan = "3" height="15%"> <b><u><center>EUROPIA!</center></u></b> </td> </tr> <tr> <td width="10%"> <iframe src="/navigation/<?php echo $navigation; ?>" frameborder="0" width="100%" scrolling="no" height="100%"></iframe> </td> <td height="80%" width="90%"> <center> <big><?php echo "<font color='" . $color . "'>" . $text . "</font></big>"; if ($page == 1) { echo '<form action="" method="POST"><table border="0"><tr><td colspan="2"><center><big>Launch a Rocket on:</big></center></td></tr>'; $getAll = mysql_query("SELECT * FROM regions WHERE region_ruler_id <> '$userID'") or die(mysql_error()); while ($regions = mysql_fetch_array($getAll)) { echo '<tr><td><b>' . $regions['region_name'] . '</td><td><input type="radio" name="region" value="' . $regions['region_id'] . '"></td></tr>'; } echo '<tr><td colspan="2"><input type="submit" name="one" value="Next"></td></tr></table></form>'; } elseif ($page == 2) { ?> <form action='' method='POST'><table border='0'><tr><td><center><big>Name</big></center></td><td><center><big>In Stock</big></center></td><td><center><big>Choose type</big></center></td></tr> <?php $getAllWeap = mysql_query("SELECT weapons.*,army.* FROM weapons INNER JOIN army ON army.weapon_name = weapons.name WHERE (army.region_id = '$SRRL') AND (weapons.type='offensive')") or die(mysql_error()); while ($weapons = mysql_fetch_array($getAllWeap)) { echo '<tr><td>' . $weapons['name'] . '</td><td><center>' . $weapons['ammount'] . '</center></td><td><input type="radio" name="rocktype" value="' . $weapons['name'] . '"></td></tr> <tr><td colspan="3"><input type="submit" name="two" value="Next"></td></tr>'; } ?> </table></form> <?php }elseif($page == 3) { echo '<form action="" method="POST"><table border="0"><tr><td>Ammount of rockets you want to fire: </td><td><input type="text" name="ammrock"></td></tr><tr><td><i>You can fire ' . $ammount . ' rockets</i></td><td><center><input type="submit" name="three" value = "Launch"></center></td></tr></table></form>'; } ?> </center> </td> </tr> </table> </body> </html> Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted May 3, 2009 Author Share Posted May 3, 2009 Still nobody? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 3, 2009 Share Posted May 3, 2009 Are you learning php, developing php code, and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON in your php.ini to get php to help you? Doing so would save you a huge amount of time find things like the problem in - $result = mysql_query($result); - that was preventing the query from even working. Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted May 3, 2009 Author Share Posted May 3, 2009 Where have I done that? or is ist just an example? And I dunno if it is on, because I'm on a free webserver :s, I can ofcourse try it on my Wamp-server. Or isn't that possible? I'm not good in finding problems Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 3, 2009 Share Posted May 3, 2009 on my Wamp-server You should be developing and debugging php code on your local development system, where you can easily change the php.ini settings. Trying to develop php code on a live server has a couple of major problems. It is a huge waste of time making a change, uploading it, and trying it. It is also very insecure. Until code is completed and tested it often contains security holes that would allow a hacker to break into your script and do what ever he wants on your web site. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted May 3, 2009 Share Posted May 3, 2009 Plus display_errors should be turned off on a live server (though still with error_reporting = E_ALL). Quote Link to comment 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.