homepage Welcome to WebmasterWorld Guest from 54.197.130.16
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
php & mySQL
displaying results from combo box into a table
ryanoasis




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

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




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

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




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

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




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

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




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

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




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

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




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

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




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

Crap. thought I tried that. Thanks!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved