Forum Moderators: coopster

Message Too Old, No Replies

Multiple List/Menus but need only one ID stored (PHP)

How do I get an ID from a list menu and store it?

         

ChiChee

8:01 pm on Feb 19, 2006 (gmt 0)

10+ Year Member



I'm very new to PHP/MySQL and struggling along. Here's the problem:

I have two Select lists that are populated dynamically from a table containing, among other things, item_id and item_name.

One Select is sorted by item_id the other Select is sorted by item_name. I'm doing this because the user may not know the item_id but they could know the item_name. In any case, I need to trap the item_id from either Select list.

Here is a snippet of the code for the form:

<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction;?>">
<table width="100%">
<tr>
<td colspan="3"><strong>
<label>
<select name="item_id" size="1" id="item_id">
<option value="value">Item ID</option>
<?php
do {
?>
<option value="<?php echo $row_rsItemID['item_id']?>"><?php echo $row_rsItemID['item_id']?></option>
<?php
} while ($row_rsItemID = mysql_fetch_assoc($rsItemID));
$rows = mysql_num_rows($rsItemID);
if($rows > 0) {
mysql_data_seek($rsItemID, 0);
$row_rsItemID = mysql_fetch_assoc($rsItemID);
}
?>
</select>
</label>
or
<select name="item_name" id="item_name">
<option value="value">Item Name</option>
<?php
do {
?>
<option value="<?php echo $row_rsItemName['item_name']?>"><?php echo $row_rsItemName['item_name']?></option>
<?php
} while ($row_rsItemName = mysql_fetch_assoc($rsItemName));
$rows = mysql_num_rows($rsItemName);
if($rows > 0) {
mysql_data_seek($rsItemName, 0);
$row_rsItemName = mysql_fetch_assoc($rsItemName);
}
?>
</select>

-- end snip --

How do I trap the user's input from either list selected and ensure that the item_id is stored in the database?

I've toyed with populating a hidden field but I can't get that to work.

Thank you for any help you can provide...I'm flying blind her.

ChiChee

8:49 pm on Feb 19, 2006 (gmt 0)

10+ Year Member



Never mind. I think I've figured it out. For those who wonder what the solution was that I found, here it is:

I created a variable named $item_ID_pass and placed the following line directly before the </select> statement.

<?php $item_ID_pass = $row_rsItemName['item_id']?>

then just at the end of my form before the </form> I have these two lines:

<input type="hidden" name="MM_insert" value="form1">
<input name="item_ID_store" type="hidden" value="<?php echo $item_ID_pass?>">

And in my insert command, I have mapped the item_ID_store to the item_ID in the file.

Works fine. Can't say I understand it all but it works.