Submitting different values

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
ECJughead
Forum Newbie
Posts: 13
Joined: Fri Mar 07, 2008 9:14 am

Submitting different values

Post by ECJughead »

Hello Board...

I have been successful in running a query to put values into a list for the user to choose from in a form. However, I don't want that value entered into my table, I want its corresponding id value.

For instance: table1 has "apples" with id=1, "oranges" with id=2, etc... My other table has a field "fruit_id" where it equals table 1's id (one-to-many relationship). The question is: how do you get it to submit the id value?

My form is already set and can submit data into my database, this is the only piece I'm missing.

Thanks
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Submitting different values

Post by RobertGonzalez »

Moved to PHP - Code.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Re: Submitting different values

Post by Ambush Commander »

When you build the form, use the ID as the value for each of the options.
ECJughead
Forum Newbie
Posts: 13
Joined: Fri Mar 07, 2008 9:14 am

Re: Submitting different values

Post by ECJughead »

Will the drop-down list show numbers or names? I prefer the names...my current code is below:

<?php
$type_set = @mysql_query('SELECT type FROM types');
if (!$type_set) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
while ($row = mysql_fetch_array($type_set)) {
echo "<option value=\"{$row['type']}\">{$row['type']}</option>";
}
?>

Do I need to pull out my id field as well as the type field? How is the id captured in the _POST string so it can be submitted into the database?
bertfour
Forum Commoner
Posts: 45
Joined: Fri Mar 07, 2008 7:33 am

Re: Submitting different values

Post by bertfour »

Code: Select all

echo "<option value=\"{$row['type']}\">{$row['type']}</option>";
Names...

Why do you use {$row['type']} and not $row['type'] ??

I guess you mean

Code: Select all

echo "<option value=\"$row['id']\">$row['type']</option>";
?
ECJughead
Forum Newbie
Posts: 13
Joined: Fri Mar 07, 2008 9:14 am

Re: Submitting different values

Post by ECJughead »

bertfour wrote:

Code: Select all

echo "<option value=\"{$row['type']}\">{$row['type']}</option>";
Why do you use {$row['type']} and not $row['type'] ??

?
I guess I could lose the brackets but it worked so I left it alone. Thanks for the code...it's still not posting in the database but it must have to do with my process page. Looking at it now.
Post Reply