Page 1 of 1

value is always woods, even if i select house...

Posted: Fri Apr 16, 2004 6:27 pm
by andycruickshank
:(

Code: Select all

<?php
foreach ($HTTP_POST_VARS as $key => $value)
{
$region =$key;
$danger =$value;
}

include ("animalhunt.php");

$sql1 = "SELECT regionID FROM regions WHERE region = '$region'"; 
$r = mysql_query($sql1) or die(mysql_error()) ;

while ($row = mysql_fetch_array($r))
  {
     extract($row);
     $region_ID = $regionID;
  }

$sql2 = "SELECT name, pic FROM $danger WHERE regID LIKE '$region_ID' ORDER BY name ASC"; 
$r2 = mysql_query($sql2) or die(mysql_error()) ;
$rowCheck = mysql_num_rows($r2); 
if($rowCheck > 0){ 
  /* Display results in a table */
  echo "<h1>$danger types</h1>";
  echo "Identify the source if possible and click the button next to it, taking care to avoid another person being affected.  Identification is not necessary, but may be helpful. <br>";
  echo "<table cellspacing='15'>";
  echo "<tr><td colspan='8'><hr></td></tr>";
  echo "<tr>\n
           <td>If you didn't see, it's ok, just select the kind of area you were in at the time or suspected time of infection.</td>\n
           <td>";
		   $habitatcheck = "SELECT DISTINCT habitat FROM habitat ORDER BY habitat";
$habitatcheckresult = mysql_query($habitatcheck)or die ("Couldn't execute query.");
/* create form containing selection list */
  echo "<form action='processhabitat.php' method='post'>
        <select name='habitat'>\n";

  while ($row = mysql_fetch_array($habitatcheckresult))
  {
     extract($row);
     echo "<option value='$habitat'>$habitat\n";
  }

  echo "</select>\n";
  echo "<input type='hidden' name='$danger' value='$habitat'>
  <input type='submit' value='Select Habitat'>
        </form>\n";
     echo "<tr><td colspan='3'><hr></td></tr>\n";
  while ($row = mysql_fetch_array($r2))
  {
     extract($row);
      echo "<tr>\n
           <td>$name</td>\n
           <td>";?> <img src="<?php echo "$pic";?>" alt="<?php echo "$name";?>" hspace="10" vspace="10" align="left" border="0" /><?php echo "</td>
		   <td><form action='processlookedlike.php' method='post'>
		<input type='hidden' name='$danger' value='$name'>
		<input type='submit' value='continue'>
        </form>\n
		   </tr>\n"; 
     echo "<tr><td colspan='3'><hr></td></tr>\n";
  }
  echo "</table>\n";
}
else{
	echo "<h1>No sources available</h1>";
	echo "We are sorry, either no information has been entered into the database or there are no sources in your area<p>
  		However, it is not infeasable that a source not native to this area has made it's way in one way or another, and we would strongly reccomend that if you have any doubts or worries, see a doctor or go to the local hospital. <br>";
}
?>
This is the code i have for listing snakes in a region. If the user saw what bit them, they click the button next to it and it sends them to the page which displays the specific info for them. If they didn't see it, they need to select a place it happened (habitat) from the drop down list. Every time i do this, and print the value of the habitat, say i selected river and pressed continue, i get woodlands, not the one i selected! Can anyone see why???

ooh, gettin the values.... oops

Posted: Fri Apr 16, 2004 6:29 pm
by andycruickshank

Code: Select all

<?php
foreach ($HTTP_POST_VARS as $key => $value)
{
$danger_type = $key;
$habitat = $value;
}
echo "$danger_type<br>";
echo "$habitat<br>";
?>
here be the code i use to get the values sent... incase it helps...

Posted: Fri Apr 16, 2004 7:41 pm
by Steveo31
Not sure if this solves, but you are missing </option> here:

Code: Select all

while ($row = mysql_fetch_array($habitatcheckresult))
  {
     extract($row);
     echo "<option value='$habitat'>$habitat\n";
  }

fair point

Posted: Fri Apr 16, 2004 7:56 pm
by andycruickshank
Steveo31 wrote:Not sure if this solves, but you are missing </option> here:

Code: Select all

while ($row = mysql_fetch_array($habitatcheckresult))
  {
     extract($row);
     echo "<option value='$habitat'>$habitat\n";
  }
put it in and it made no difference....

good programming to close it tho, i guess... one in an earlier web page didn't have it and worked fine! both :lol: and :cry: at the same time! :? Thanks for tryin tho Steveo! :)

Posted: Sat Apr 17, 2004 4:44 am
by JAM
Looking at this at the top:

Code: Select all

foreach ($HTTP_POST_VARS as $key => $value)
{
$region =$key;
$danger =$value;
}
Then take the following example in cosideration:

Code: Select all

<pre>
<?php
$array[] = 'foo';
$array[] = 'bar';
// how foreach can be used...
foreach($array as $key => $val) {
    echo $key .' : '. $val .'<br />';
}

// what you are doing, note the result...
foreach($array as $key => $val) {
    $danger = $key;
    $habitat = $val;
}
    echo $danger .' : '. $habitat .'<br />';
?>
Result:

Code: Select all

0 : foo
1 : bar
1 : bar
Note that the last output example allways will print only "1 : bar".

As you are using a foreach() loop, the $danger and $habitat will allways be declared using the last values being sendt from the form, in this case the <hidden> field that you are using after the <option>'s.

Hope I made sence.

think so...

Posted: Sat Apr 17, 2004 6:44 am
by andycruickshank
yeah, i think i get that, but if i am selecting a value, am i not only sending one set of values, so the foreach should just set the variables to the danger (preset) and the habitat (from the list)?

Am i talking sense, or is that not how it works...?

:?

Thanks

Andy