Hi and thanks in advance to anyone who can help me.
I have two php pages. The first page contains all records in a database the user can then select a record and edit it - bringing them to the editRecord page. On the edit record page the information about the record once again appears in text boxes to allow the user to change whatever they wish however a few fields are made up of dropdownlists - which are also populated from a database.
- My Problem is: on the editRecord page I want the dropdown list to have the item selected that was previously saved in the database. I have tried several different things but nothing is working for me.
Here is the code I am using:
<?PHP
//sql statement to read the value that are currently saved for the record
$sql= "Select * from redo where counter ='$counter'";
$result=mysql_query($sql, $db);
if($myrows = mysql_fetch_array($result)){
do{
//$date does not use dropdown list
$date=$myrows["Date"];
//$type will use a dropdown list
$type=$myrows["Type"];
}while($myrows=mysql_fetch_array($result));
}
?>
<Table align ="center">
<tr>
<tr></tr>
//date field is populated
<td colspan =2 align="Right"><B>Date:</B></td><td><input type ="TEXT" name="date" value="<?PHP echo "$date"?>";></td>
</tr>
<tr>
<tr></tr>
<td colspan =2 Align ="Right"><B>Type:</B></td>
<td>
//code to populate the dropdown list
<?PHP
$db = mysql_connect("12.1.0.0", "root");
mysql_select_db("RedoDatabase", $db);
$sql ="SELECT Type From typedescription";
$result=mysql_query($sql, $db);
$rowResult2=mysql_fetch_assoc($result);
$totalRows2=mysql_num_rows($result);
//I am not sure if the selected ='.$type.' is correct here?
echo "<select name = type selected ='.$type.'>";
while(list($type)=mysql_fetch_row($result)){
echo "<option value='$type'>$type</option>\n";
}
echo "</select>";
?>
</td>
I have two php pages. The first page contains all records in a database the user can then select a record and edit it - bringing them to the editRecord page. On the edit record page the information about the record once again appears in text boxes to allow the user to change whatever they wish however a few fields are made up of dropdownlists - which are also populated from a database.
- My Problem is: on the editRecord page I want the dropdown list to have the item selected that was previously saved in the database. I have tried several different things but nothing is working for me.
Here is the code I am using:
<?PHP
//sql statement to read the value that are currently saved for the record
$sql= "Select * from redo where counter ='$counter'";
$result=mysql_query($sql, $db);
if($myrows = mysql_fetch_array($result)){
do{
//$date does not use dropdown list
$date=$myrows["Date"];
//$type will use a dropdown list
$type=$myrows["Type"];
}while($myrows=mysql_fetch_array($result));
}
?>
<Table align ="center">
<tr>
<tr></tr>
//date field is populated
<td colspan =2 align="Right"><B>Date:</B></td><td><input type ="TEXT" name="date" value="<?PHP echo "$date"?>";></td>
</tr>
<tr>
<tr></tr>
<td colspan =2 Align ="Right"><B>Type:</B></td>
<td>
//code to populate the dropdown list
<?PHP
$db = mysql_connect("12.1.0.0", "root");
mysql_select_db("RedoDatabase", $db);
$sql ="SELECT Type From typedescription";
$result=mysql_query($sql, $db);
$rowResult2=mysql_fetch_assoc($result);
$totalRows2=mysql_num_rows($result);
//I am not sure if the selected ='.$type.' is correct here?
echo "<select name = type selected ='.$type.'>";
while(list($type)=mysql_fetch_row($result)){
echo "<option value='$type'>$type</option>\n";
}
echo "</select>";
?>
</td>