Page 1 of 1

Submitting different values

Posted: Fri Mar 07, 2008 9:26 am
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

Re: Submitting different values

Posted: Fri Mar 07, 2008 11:10 am
by RobertGonzalez
Moved to PHP - Code.

Re: Submitting different values

Posted: Fri Mar 07, 2008 10:56 pm
by Ambush Commander
When you build the form, use the ID as the value for each of the options.

Re: Submitting different values

Posted: Sat Mar 08, 2008 9:35 am
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?

Re: Submitting different values

Posted: Sat Mar 08, 2008 9:42 am
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>";
?

Re: Submitting different values

Posted: Sat Mar 08, 2008 9:57 am
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.