Simple }else{ statement not working

I’m puzzled why my else statement is not working. It’s pretty straightforward - if the ‘tier_level2_item’ field was left blank, then assign “none” to the variable:

if (isset($_POST['tier_level2_item'])) {
	$tier_level2_item = $_POST['tier_level2_item'];
	$tier_level2_item = mysql_real_escape_string($tier_level2_item); 
}else{ $tier_level2_item = "none"; }

When the field is left blank, “none” should be inserted into the table; instead, nothing is inserted into the table for this field.

I’ve tried single quotes around ‘none’ and that doesn’t work either. The following should say “none” when left blank, but “none” does not show:

		<?php echo "<p>Level 2 Item name: <strong>" . $tier_level2_item . "</strong></p>"; ?>

All other fields in the code work fine except this one. No error message given.

Thanks!
Steve

isset() tests whether a variable exists, not what its value is.


$var = '';
isset($var); //true

$_POST[‘tier_level2_item’] will always exist once the form has been posted.

Try


if($tier_level2_item = trim($_POST['tier_level2_item'])) {
   $tier_level2_item = mysql_real_escape_string($tier_level2_item);
}
else {
   $tier_level2_item = 'none';
}

Ahhh … I see the mistake. Thanks for the correction!

Regards,
Steve