PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?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???
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 and at the same time! Thanks for tryin tho Steveo!
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.
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...?