Drop-down list not working

I have a drop-down of about 20 names in a form. In case none of the names are appropriate, I also include a text box for entering an alternate name. Upon submitting, the name will be inserted into a mysql database field: “tier_item_brand.” However, the drop-down is not inserting anything.

<p>A. <select size="1" name="tier_item_brand">
<option value=""></option>
<option value="name1">name1</option>
<option value="name2">name2</option>
<option value="name3">name3</option>
</select></p>

<p>B. <input type="text" name="tier_item_brand" value="" maxlength="255"  /></p>

How can I make both useable?

Thanks!
Steve

I assume you’re using PHP to handle the posted data? When you use $_POST[‘tier_item_brand’] you will always get the value from the input element, since the select box and the input element have the same name and the input element is the last one in the code. So you’ll never get the value from the select box…

Just give the input element a different name, like “tier_item_brand_alt” or whatever, and check for both $_POST[‘tier_item_brand’] and $_POST[‘tier_item_brand_alt’] in your PHP code.

Of course! That makes sense!

Thanks!
Steve

OK, this is not inserting drop-down figures, only textbox entries:

// brand1 = drop-down. brand2 = textbox.
if (isset($_POST['tier_item_brand1'])){
	$tier_item_brand = $_POST['tier_item_brand1'];
	$tier_item_brand = mysql_real_escape_string($tier_item_brand);
	}else{
if (isset($_POST['tier_item_brand2']))
	$tier_item_brand = $_POST['tier_item_brand2'];
	$tier_item_brand = mysql_real_escape_string($tier_item_brand);
	}

$cover_tiers = mysql_query("INSERT INTO cover_tiers SET
tier_level = '$tier_level',
tier_item_name = '$tier_item_name',
tier_item_brand = '$tier_item_brand'");

What’s the right way to go about this?

Thanks!
Steve

To check, check then check again.

Save the ‘compiled’ SQL to a variable, then check if the query executed successfully, if not, use mysql_error to find out why and display the SQL you stored in the variable for reference.

OK, now I have it. I validated the drop-down input more strictly in terms of string length.

if (isset($_POST['tier_item_brand1']))
	$tier_item_brand = $_POST['tier_item_brand1'];
	if (strlen($tier_item_brand) > 0) // validate input. "php and mysql" p47.
	{
	$tier_item_brand = mysql_real_escape_string($tier_item_brand);
	}else{
if (isset($_POST['tier_item_brand2']))
	$tier_item_brand = $_POST['tier_item_brand2'];
	$tier_item_brand = mysql_real_escape_string($tier_item_brand);
	}

Finally it will take data entered into either box. Now I need to go the extra mile to make sure only ONE box has data!