Forum Moderators: coopster
I have a page with a combo box that holds information, the users selects one of the options and the page is sent back to itself. The choice they select each contain a primary key, and I just want to be able to display the primary key below in some H1 tags for now (later I will throw it in my select statement). I am having trouble passing the variable to get displayed. I can type it in the http header and it works but I can't have the page do it.
<form name="frmClass" action="register.php?optClass=<?=$objRow["lngClassPK"]?>" method="post">
<select>
<option selected>Select a course:</option>
<?while ($objRow = mysql_fetch_array($objRec)) {
?>
<option name="optClass" value="<?=$objRow["lngClassPK"]?>">#<?=$objRow["strNum"]?> - BLD: <?=$objRow["strBuilding"]?> - RM: <?=$objRow["strRoom"]?> - TIME: <?=$objRow["dtmBegTime"]?> - <?=$objRow["strDay"]?></option>
<?}?>
</select>
<input type="Submit" name="cmdSubmit" value="Select">
<h1><?=$optClass?></h1><!-- this is just to test it -->
</form>
I think im submiting it wrong or it has something to do with my option tag: value="<?=$objRow["lngClassPK"]?>"
any ideas would be helpful, and yes I know sessions would be better, but I just want this to work first
I think the main problem is this: action="register.php?optClass=<?=$objRow["lngClassPK"]?>" method="post"> - you would be using POST and GET at the same time. usually the script would get a value for optClass back and could use that to re-lookup the associated data in the database in order to give feedback on what's been selected.
Does that make sense?
are you saying to change the mehod to = "get" instead of post
Because when I change it to get it sends the submit buttons information.
This is what I have now:
<form action="register.php?class=<?=$optClass?>" method="post">
<select>
<option class="bodytabledata2" selected>Select a course:</option>
<?while ($objRow = mysql_fetch_array($objRec)) {?>
<option name="class" value="<?=$objRow["lngClassPK"]?>">
#<?=$objRow["strNum"]?> - BLD: <?=$objRow["strBuilding"]?> - RM: <?=$objRow["strRoom"]?> - TIME: <?=$objRow["dtmBegTime"]?> - <?=$objRow["strDay"]?>
</option>
<?}?>
</select>
<input type="Submit" name="cmdSubmit" value="Select">
<h1><?=$_GET["class"]?></h1>
</form>
?class=<?=$optClass?> at the action specification because this information will be submitted through the form (by post). You don't need to include variables in the action URL. At least it's worth a try removing it ...
it may or may not be the primary problem it is a problem. When the form is submitted you are trying to set the same var twice. You will never get what you think. If you need them both there for some reason one should have a different name.
I would try it without the get string in the action and see what it gives you. It may require a logic change or two but the method right now is flawed because of the double setting of the var.
################## Register Page ##################
<form action="foo.php" method="post">
<select>
<option selected>Select a course:</option>
<?while ($objRow = mysql_fetch_array($objRec)) {?>
<option name="optClass" value="<?=$objRow["lngClassPK"]?>">
#<?=$objRow["strNum"]?> - BLD: <?=$objRow["strBuilding"]?> - RM: <?=$objRow["strRoom"]?> - TIME: <?=$objRow["dtmBegTime"]?> - <?=$objRow["strDay"]?>
</option>
<?}?>
</select>
<select>
<option name="foo" value="you have foo"> foo foo</option>
</select>
<input type="Submit" name="cmdSubmit" value="Select">
</form>
################## foo Page ##################
<html>
<body>
<h1>GET VAL:<?=$_GET["optClass"]?></h1>
<h1>VAL:<?=$optClass?></h1>
<h1>POST VAL:<?=$_POST["optClass"]?></h1>
<br />
for foo.........
<h1>GET VAL:<?=$_GET["foo"]?></h1>
<h1>VAL:<?=$foo?></h1>
<h1>POST VAL:<?=$_POST["foo"]?></h1>
</body>
</html>
The http header only gives me this:
[...........]
only gives the value of the submit button..