$_POST an OPTION value?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
synical21
Forum Contributor
Posts: 150
Joined: Tue Jul 28, 2009 8:44 am
Location: London UK

$_POST an OPTION value?

Post by synical21 »

I am trying to post the value of a <select> field, I have googled around but my problem gets worse rather than better. Here is the current code:

Code: Select all

 
<SELECT onChange="final_cat_and_price()" SIZE=9 NAME=Sub Id=Sub>
<OPTION value=0000>Click 2x</OPTION>
<OPTION value=0001>Click 3x</OPTION>
<OPTION value=0002>Search + Click 1x</OPTION>
<OPTION value=0003>Search + Click 2x</OPTION>
</SELECT>
<SELECT onChange="final_cat_and_price()" SIZE=9 NAME=Sub Id=Sub>
<OPTION value=0200>1 Page</OPTION>
<OPTION value=0201>2 Pages</OPTION>
<OPTION value=0202>3 Pages</OPTION>
<OPTION value=0203>4 Pages</OPTION>
</SELECT>
 
As you can see each option has a value, how could i post that value to a new page so i can use the data?
Trahb
Forum Commoner
Posts: 36
Joined: Sat Jan 30, 2010 9:09 pm

Re: $_POST an OPTION value?

Post by Trahb »

There's probably a better way, but I store the value in a variable of one of my classes and call it on the other page.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: $_POST an OPTION value?

Post by AbraCadaver »

Are you asking how you post it? Or how do you access it on the next page or what?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
synical21
Forum Contributor
Posts: 150
Joined: Tue Jul 28, 2009 8:44 am
Location: London UK

Re: $_POST an OPTION value?

Post by synical21 »

how I would access it on another page, then insert the value into the DB. My bad
Alkis
Forum Commoner
Posts: 31
Joined: Fri Mar 26, 2010 8:41 am

Re: $_POST an OPTION value?

Post by Alkis »

You need to include the form fields inside a <form> tag, to actually have a working form watch the -> action="anotherpage.php" <- witch actually informs the browser where to post the data inside the form. Rename it to what to receiving page is. Note also a new button entry, the "Submit". This will be the button which will actually post the form to the "action" page.

Code: Select all

<form name="form1" action="anotherpage.php" method="post">
 
<SELECT onChange="final_cat_and_price()" SIZE=9 NAME=Sub Id=Sub>
<OPTION value=0000>Click 2x</OPTION>
<OPTION value=0001>Click 3x</OPTION>
<OPTION value=0002>Search + Click 1x</OPTION>
<OPTION value=0003>Search + Click 2x</OPTION>
</SELECT>
 
<input type="submit" value="Submit" />
 
</form>

And then on anotherpage.php you will get the the selected value from the Sub select and assign it to the $sub variable, and do with it what you want:

$sub = $_POST['Sub'];
Post Reply