Post different data to what is show in a html select input

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
lshaw
Forum Commoner
Posts: 69
Joined: Mon Apr 20, 2009 3:40 pm
Location: United Kingdom

Post different data to what is show in a html select input

Post by lshaw »

I have a drop down list stored in a database, but when the user submits data I need to submit the id of the record, not the actual value or I will have duplicative data

Example:

Code: Select all

 
//fetch array code etc.
//while loop {
    echo "<option>$array['name']</option>"; //show the option list
    //what I want to submit is the $array['id'] of the name they selected. 
}
 
I know this could be done with ajax by updating a hidden fieild when the value of the select is changed, but i dont what to use ajax.

Thanks for your help

Lewis
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Post different data to what is show in a html select input

Post by AbraCadaver »

Maybe?

Code: Select all

echo "<option value=\"{$array['id']}\">{$array['name']}</option>";
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.
Post Reply