Jump to content

I dunno whats the problem


DEVILofDARKNESS

Recommended Posts

The folowing page doesn't work, it only shows the table header:

 

SO you have clicked on the button with name '1' wich is a submit button from a form with method post:

<?php
session_start();
require_once 'login-check.php';
				require_once ""; //File is left away for security 
				$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);
$page = $_GET['page'];
if($_POST['1']){
$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 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";
}
?>
<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>"; ?><br>
				Launch a Rocket on:</big>
<form action='' method='post'>
$query = "SELECT offensive_level FROM nations WHERE nation_id = '$nationid'";
$result = mysql_query($query);
list($offence) = mysql_fetch_row($result);
$query = "SELECT defensive_level FROM nations WHERE nation_id = '$nationid'";
$result = mysql_query($query);
list($defence) = mysql_fetch_row($result);
?>
<table border='0'><tr><td>Weapon Type</td><td>Ammount of Rockets you can fire</td><td>Ammount of Rockets you want to fire</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>" . $weapons['ammount'] . "</td><td><input field='radio' name='rocktype' value='" . $weapons['id'] . "'></td></tr>";
}
?>
</table></form>
				</center>
			</td>
		</tr>

	</table>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/155394-i-dunno-whats-the-problem/
Share on other sites

correction it is there!, I just didn't gave the full code, and because I thought I had cut everything right, their could be some things be left, here is the full code:

<?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;
}
$page = $_GET['page'];
if($_POST['1']){
$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 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['2']) {
if($_POST['ammrock'] > $rockets) {
	$text = "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'];
$_SESSION['RUA'] = $_POST['region'];//RUA = Region Under Attack
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>"; ?><br>
				Launch a Rocket on:</big>
<form action='' method='post'>
<table border='0'>
<?php 
if($page == 1) {
$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='1' value='Next [1 of 2]'></td></tr></table>"; 
}elseif($page == 2) {
$query = "SELECT offensive_level FROM nations WHERE nation_id = '$nationid'";
$result = mysql_query($query);
list($offence) = mysql_fetch_row($result);
$query = "SELECT defensive_level FROM nations WHERE nation_id = '$nationid'";
$result = mysql_query($query);
list($defence) = mysql_fetch_row($result);
?>
<table border='0'><tr><td>Weapon Type</td><td>Ammount of Rockets you can fire</td><td>Ammount of Rockets you want to fire</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>" . $weapons['ammount'] . "</td><td><input field='radio' name='rocktype' value='" . $weapons['id'] . "'></td></tr>";
}
?>
</table></form>
<?php }  ?>
				</center>
			</td>
		</tr>

	</table>
</body>
</html>

see if you can find the problem now with the code indented...

<?php
  session_start();
  require_once 'login-check.php';
  //left away for security reasons
  require_once "";
  $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'];
  if ($_POST['1']) {
      $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);
      $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['2']) {
      if ($_POST['ammrock'] > $rockets) {
          $text = "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>";
?><br>
          Launch a Rocket on:</big>
<form action='' method='post'>
<table border='0'>
<?php
  if ($page == 1) {
      $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='1' value='Next [1 of 2]'></td></tr></table>";
  } elseif ($page == 2) {
      $query = "SELECT offensive_level FROM nations WHERE nation_id = '$nationid'";
      $result = mysql_query($query);
      list($offence) = mysql_fetch_row($result);
      $query = "SELECT defensive_level FROM nations WHERE nation_id = '$nationid'";
      $result = mysql_query($query);
      list($defence) = mysql_fetch_row($result);
?>
<table border='0'><tr><td>Weapon Type</td><td>Ammount of Rockets you can fire</td><td>Ammount of Rockets you want to fire</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>" . $weapons['ammount'] . "</td><td><input field='radio' name='rocktype' value='" . $weapons['id'] . "'></td></tr>";
      }
?>
</table></form>
<?php
  }
?>
          </center>
        </td>
      </tr>

    </table>
  </body>
</html>

Well see, because the script always Gave me "You Don't have enough rockets do to that ...",

I've added some outputs to see what was wrong, somehow, the $weaponname, doesn't hold a value, why?

I've tried to put it on other places in the script but it didn't work.

 

<?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;
  }
  $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['1']) {
      $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['2']) {
header('location:/attack.php?page=3');
}elseif($_POST['3']) {
$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);
      if ($_POST['ammrock'] > $ammount) {
          $text = $_POST['ammrock'] . " " . $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>";
?>
<form action='' method='post'>
<?php
  if ($page == 1) {
  echo "<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='1' value='Next [2 of 3]'></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='2' value='Next [3 of 3]'></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='3' value = 'Launch'></center></td></tr></table></form>";
  }
?>
          </center>
        </td>
      </tr>

    </table>
  </body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.