I have seen multiple posts in the forum on this, but I'm still a little confused. I'm newer to PHP and am having difficulty putting together the limited knowledge I have of arrays and populating a form.
I have information stored in a db. The code I am using to retrieve it and put it into a form so the user can update it is listed below.
My first issue is that it is not populating the radio button properly (as being checked or unchecked). It will properly check the first result from the db, but none of the others. From what I have read on the forums this problem is probably linked to not using arrays to echo the data. My first question is how do I properly retrieve the information and populate the form? This also leads to my second question, how do I submit this information to the database to update multiple rows.
Any help would be greatly appreciated. Thanks in advance.
<?php
$propId = $_GET['propId'];
$sql = "SELECT imageId, propId, path, title, main FROM images WHERE propId = $propId";
$rows = $db->getAll($sql);
foreach ($rows as $row) {
$image = $row['path'];
$title = stripslashes($row['title']);
$main = $row['main'];
echo "<tr><td rowspan=\"3\"><img src=\"../$image\" height=\"80\" width=\"80\" /></td>
<td><label class=\"label\">Title: </label><input type=\"text\" name=\"title\" size=\"25\" maxlength=\"25\" value=\"$title\"></td></tr>";
if ($main == 'y') {
echo "<tr><td><label class=\"label\">Main Image: </label><input type=\"radio\" name=\"mainThumb\" value=\"y\" checked></td></tr>";
} else {
echo "<tr><td><label class=\"label\">Main Image: </label><input type=\"radio\" name=\"mainThumb\" value=\"y\"></td></tr>";
}
if ($main == 'n') {
echo "<tr><td><label class=\"label\">Thumbnail: </label><input type=\"radio\" name=\"mainThumb\" value=\"n\" checked></td></tr>";
} else {
echo "<tr><td><label class=\"label\">Thumbnail: </label><input type=\"radio\" name=\"mainThumb\" value=\"n\"></td></tr>";
}
echo "<tr><td> </td></tr>
<tr><td> </td></tr>";
}
?>