Welcome to WebmasterWorld Guest from 54.226.183.49

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

php & mySQL

displaying results from combo box into a table

     

ryanoasis

1:07 am on Mar 9, 2003 (gmt 0)

10+ Year Member



Okay, I don't think I will figure this out. The more I look at it the more confused I get. Please help, tell me what I am doing wrong:

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

mapostel

2:00 am on Mar 9, 2003 (gmt 0)

10+ Year Member



Hi,

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?

ryanoasis

2:36 am on Mar 9, 2003 (gmt 0)

10+ Year Member



Not really...

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>

mapostel

11:04 am on Mar 9, 2003 (gmt 0)

10+ Year Member



Sorry - my point about POST and GET not working together was not quite true. However, I still believe you'd need to get rid of
?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 ...

jatar_k

4:15 pm on Mar 9, 2003 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



mapostel is right,

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.

ryanoasis

6:22 pm on Mar 9, 2003 (gmt 0)

10+ Year Member



Stumped, thanks for the help though..
I have tried to simplify it as much as I can, I even looked in my book again and the "foo" part of this SHOULD work?

################## 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..

nosanity

7:05 am on Mar 11, 2003 (gmt 0)

10+ Year Member



For "foo" you have your syntax a little wrong. It should read:


<select name="foo">
<option value="WORKED">This should work</option>
</select>

noSanity

ryanoasis

7:40 pm on Mar 11, 2003 (gmt 0)

10+ Year Member



Crap. thought I tried that. Thanks!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month