Problem inserting an if statement?

Hello All,

Wondering if someone can help me with a tiny problem i’m having that’s driving me potty (and I know when I find the answer I will be annoyed with myself!!!).

Take this code:


$html .= '<option value="'.$key.'">'.$value.'</option>' . "\
"; 

Basically I want to add an if statement in there:


if ($input_value == ''.$key.'') echo ' selected'  

However, everytime I add the thing I get a pesky parse error?

Thanks

Are you $_POST 'ing the $input_value?
I would do echo $input_value and echo $key to see what they say,


$input_val = $_POST['the_field_here']; // <-- are you doing that?
if ($input_val == $key) echo ' selected';

echo $input_val;
echo ' <-- input | key -->';
echo $key;

if you need to fix whitespace use trim()

Use something like this . Hope it helps :slight_smile:


if ($input_value == ''.$key.'') { 
    $html .= '<option value="'.$key.'">'.$value.'</option>' . "\
"; 
} else {
    $html .= '<option value="'.$key.'" "selected"  >'.$value.'</option>' . "\
"; 
}