Jump to content


Photo

Option Select Values


  • Please log in to reply
1 reply to this topic

#1 JDPerry

JDPerry
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 18 April 2006 - 11:54 PM

I am typing the code below to pass two variables from two selection boxes to a page titled "pass_test.php".
The selection boxes are based on databases. When you look at the web page is displays propertly
and let users select the name and the empnum but when you hit the submit button it send value for the last
row in each database. I am new to both PHP and HTML so I think it is something I have structure incorrectly.
The link to the database works fine but my variable won't post. Any help would be appreciated.

thanks
JDPerry

<html>
<center>
<?php
//Get all the data from the "Period" Table
$result = mysql_query("SELECT * FROM Period") or die (mysql_error());

//Get data from the "UserInfo" Table
$result2 = mysql_query("SELECT * FROM UserInfo ORDER BY Lname") or die (mysql_error());

//Create a selection list for the UserInfo table
echo "<select name = 'EmpNum'>\n";
echo "<option value = '0'>Select a User\n";

//Retreive data until all results collected from UserInfo
while($row = mysql_fetch_array($result2))
{
extract($row);
echo "<option value = $EmpNum>$Fname $Lname\n";
}
echo "</select>\n";
echo "<br></br>";

//Create a selection list for the Period table
echo "<select name = 'PeriodID'>\n";
echo "<option value = '0'>Select a Reporting Period\n";

//Retreive data until all results collected from PERIOD
while($row = mysql_fetch_array($result))
{
extract($row);
echo"<option value = $PeriodID>$PeriodDesc\n";
}
echo "</select>\n";
echo "<br></br>";
print ("</TABLE>\n");
print ("<form action=\"pass_test.php\" METHOD=\"POST\">\n");
print ("<INPUT TYPE=\"hidden\" NAME=\"EmpNum\"
VALUE=\"{$HTTP_POST_VARS['EmpNum']}\">\n");
print ("<INPUT TYPE=\"hidden\" NAME=\"PeriodID\"
VALUE=\"{$HTTP_POST_VARS['PeriodID']}\">\n");
print ("<INPUT TYPE=\"submit\" VALUE=\"View Report\">\n");
print ("</form>\n");
print ("</CENTER>\n");
?>
</center>
</html>


#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 19 April 2006 - 12:19 AM

With that code both the dropdown selectors are generated outside your form and therefore 100% ineffective. What gets passed are the hidden values (and it's not clear what purpose that serves). Restructure your code to get the opening form tag before the dropdowns.
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users