Setting value of SELECT
Posted: Thu Apr 29, 2010 4:03 am
I am trying to create a form where the user can update a full row from a MySql db.
I want text areas and select lists to show the correct value from the database.
I am trying to do this by using value="'.$row['*****'].'"
This works on the input field but not on the select field, when the page loads it shows the top entry in the list. Can anyone explain what i am doing wrong?
Thanks
I want text areas and select lists to show the correct value from the database.
I am trying to do this by using value="'.$row['*****'].'"
This works on the input field but not on the select field, when the page loads it shows the top entry in the list. Can anyone explain what i am doing wrong?
Thanks
Code: Select all
<?php
mysql_connect ("localhost", "MyUserbame", "MyPassword") or die (mysql_error());
mysql_select_db ("enquiries") or die (mysql_error());
$enterid = $_POST['enterid'];
$sql = mysql_query("select * FROM enquiry WHERE id LIKE '$enterid'");
echo "You are about to update record number '<strong>$enterid</strong>'<br />";
echo "<br />";
print ('<table style="border-width: thin; border-style: solid; border-color: grey; cellpadding=1; border-width: 2px;">');
print '<tr bgcolor="grey">';
print '<td width="3%"><t><strong>ID</strong></t></td>';
print '<td width="9%"><t><strong>ENTRY DATE</strong></t></td>';
print '<td width="4%"><t><strong>TITLE</strong></t></td>';
print '<td width="9%"><t><strong>FIRST NAME</strong></t></td>';
print '<td width="8%"><t><strong>SURNAME</strong></t></td>';
print '<td width="8%"><t><strong>DOB</strong></t></td>';
print '</tr>';
while ($row = mysql_fetch_array( $sql ))
{
print '<tr bgcolor="lightgrey">';
print '<td width="3%"><t>'.$row['id'].'</t></td>';
print '<td width="9%"><t>'.$row['date'].'</t></td>';
print '<td width="4%"><t><select name="title" id="title" tabindex="5" value="'.$row['title'].'">
<option value="Mr">Mr</option>
<option value="Mrs">Mrs</option>
<option value="Miss">Miss</option>
<option value="Ms">Ms</option>
</select></t></td>';
print '<td width="9%"><t><input name="firstname" type="text" value="'.$row['firstname'].'" /></t></td>';
print '<td width="8%"><t>'.$row['surname'].'</t></td>';
print '<td width="8%"><t>'.$row['dob'].'</t></td>';