Jump to content

Option Select Values


JDPerry

Recommended Posts

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>
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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