Question

I am able to successfully pre-populate my questions using the following code: First Name: <input type="text" name="first_name" size="30" maxlength="20" value="' . $row[2] . '" /><br />

However, when I try to do the same for a drop down box and a textarea box, nothing is pre-populated from the database, even though there is actual content in the database. This is the code I'm using for the drop down and textarea, respectively:

<?php echo ' <form action ="edit_contact.php" method="post"> <div class="contactfirstcolumn"> Prefix: <select name = "prefix" value="' . $row[0] . '" /> <option value="blank">--</option> <option value="Dr">Dr.</option> <option value="Mr">Mr.</option> <option value="Mrs">Mrs.</option> <option value="Ms">Ms.</option> </select><br />'; ?>

AND

Contact Description:<textarea id = "contactdesc" name="contactdesc" rows="3" cols="50" value="' . $row[20] . '" /></textarea><br /><br />

It's important to note that I am not receiving any errors. The form loads fine, however without the data for the drop down and textarea fields.

Thanks! Tony

No correct solution

OTHER TIPS

Select doesn't work that way.

If you want to pre populate select, you can try this way:

$predata = array(
    'blank' => '--',
    'Dr' => 'Dr.',
    'Mr' => 'Mr.',
    'Mrs' => 'Mrs.',
    'Ms' => 'Ms.',
);

echo "<select name='prefix'>";
    foreach($predata as $value => $label){
        echo "<option value='$value' ".($value == $row[0] ? 'selected="selected"' : '').">$label</option>";
    }
echo "</select>";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top