开发者

Trouble pre-populating drop down and textarea from MySQL Database

开发者 https://www.devze.com 2022-12-25 05:12 出处:网络
I am able to successfully pre-populate myquestions using the following code: First Name: <input type=\"text\" name=\"first_name\" size=\"30\" maxlength=\"20\" value=\"\' . $row[2] . \'\" /><b

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 dro开发者_StackOverflowp 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


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>";
0

精彩评论

暂无评论...
验证码 换一张
取 消