I have a form that is built based on a query. Everything is working except when I submit the form the radio buttons are only updating the first row in my database. dcategory and dthumbnail are two radio buttons that I have for each one of the rows in the table. I've tried using a hidden input object for each of the radio button groups to store the values in but clearly I'm having a mental block because I can't get that to work right either. So any new ideas would be appreciated. Thanks!
[PHP]
// form
$result = mysql_query("Select * from portfolio where projectname='$projectname' order by photoid");
if ($result)
{
?>
<form name='Proj' action='<?php echo $_SERVER['PHP_SELF']?>' method='post'>
<?php
print "<table><tr><td></td><td></td><tr>";
$count=mysql_num_rows($result);
while ($array= mysql_fetch_assoc($result))
{
$photoid = $array['photoid'];
$category = $array['category'];
$projectname = $array['projectname'];
$subname = $array['subname'];
$location = $array['location'];
$desc1 = $array['desc1'];
$dcategory = $array['dcategory'];
$dthumbnail = $array['dthumbnail'];
print "<input type='hidden' name=photoid[] value=$photoid />";
print "<tr><td><img src=$location style='cursor: pointer;' name=location[] width='216' height='144' border'0'/></td><td>";
if($dcategory=='Y')
{
print "Default Photo for Category?<input name='dcategory[]' type='radio' value='Y' checked='checked'/>";
}
else
{
print "Default Photo for Category?<input name='dcategory[]' type='radio' value='N' />";
}
if($dthumbnail=='Y')
{
print "Default Photo for Project?<input name='dthumbnail[]' type='radio' value='Y' checked='checked'/>";
}
else
{
print "Default Photo for Project?<input name='dthumbnail[]' type='radio' value='N' />";
}
print "<table><tr><td>Category:</td>";
print "<td><input type='text' name=category[] value=$category></td></tr>";
print "<tr><td>Project:</td>";
print "<td><input type='text' name=projectname[] value=$projectname></td></tr>";
print "<tr><td>Sub Title:</td>";
print "<td><input type='text' name=subname[] value=$subname></td></tr>";
print "<tr><td>Description:</td>";
print "<td><input type='text' name=desc1[] value=$desc1></td></tr>";
print "</table>";
}
print "</tr></table>";
print "<input type='submit' name='SubmitProj' value='Submit'>";
print "</form>";
}
}
// If user has submitted
if(isset($_POST["SubmitProj"]) && trim($_POST["SubmitProj"])!=='')
{
// Itirate the objects of the form
foreach($_POST['photoid'] as $key=>$photoid)
{
$update ="UPDATE portfolio SET category='".$_POST['category'][$key]."', projectname='".$_POST['projectname'][$key]."', subname='".$_POST['subname'][$key]."', desc1='".$_POST['desc1'][$key]."', dcategory='".$_POST['dcategory'][$key]."', dthumbnail='".$_POST['dthumbnail'][$key]."' WHERE photoid='$photoid'";
$result = mysql_query($update);
}
}[/PHP]