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
Submitting different values
Moderator: General Moderators
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: Submitting different values
Moved to PHP - Code.
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
Re: Submitting different values
When you build the form, use the ID as the value for each of the options.
Re: Submitting different values
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?
<?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
Names...Code: Select all
echo "<option value=\"{$row['type']}\">{$row['type']}</option>";
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
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.bertfour wrote:Why do you use {$row['type']} and not $row['type'] ??Code: Select all
echo "<option value=\"{$row['type']}\">{$row['type']}</option>";
?