ich hab da ein problem mit den checkboxen. ich holl mir zb. 15 datensätze aus der db und generiere dynamisch ein formular mit checkboxen. wenn ich jetzt nur 1-2 gecheckt habe und auf senden klicke speichert er mir nicht zb. den 5 u. 6 datensatz sondern den letzten? ich kann nur etwas korrekt updaten wenn ich alle checkboxen aktiviere.
	
							
						
					PHP-Code:
	
	
das ist die formular.php:
<form action="check.php" name="form1" method="POST" enctype="multipart/form-data">
  <fieldset><legend>checking</legend>    
     <?
$query20 = mysql_query("select COUNT(id) from newsart");
         list($homeanzahl)=mysql_fetch_row($query20);
  $a = 1;    
for($i = 0; $i < $homeanzahl; $i++){
$query = mysql_query("SELECT * FROM newsart where homeid = $a ORDER BY id ASC ");
    $cat = mysql_fetch_array($query);
   
                                 $checkid[$a] = $cat[id];
                                 $home_id[$a] = $cat[homeid];
         $home_title[$a] = $cat[title];
         $home_description[$a] = $cat[description];
         $home_image[$a] = $cat[image];
         $home_link[$a] = $cat[hyperlink];
         $home_breite[$a] = $cat[breite];
         $home_hoehe[$a] = $cat[hoehe];
?>
              
            <table width="" border="0" cellpadding="0" cellspacing="0"  height="100%">
              <tr> 
                <td valign="top" class="newstop">ID:</td>
                <td valign="top" class="newstop"><label><? echo $checkid[$a] ?></label> 
                   </td>
                <td width="49" rowspan="6" valign="top" class="newstop">Link: 
                </td>
                <td width="49" rowspan="6" valign="top" class="newstop"><textarea name="hyperlinks[<? echo $a ?>]" cols="40" rows="10" id="hyperlinks"><? echo $home_link[$a] ?></textarea></td>
                <td width="24" rowspan="6" valign="top" class="newstop">Beschreibung: 
                </td>
                <td width="12" rowspan="6" valign="top" class="newstop"><textarea name="beschreibung[<? echo $a ?>]" cols="40" rows="10" id="beschreibung"><? echo $home_description[$a] ?></textarea></td>
                <td width="13" rowspan="6" valign="top" class="newstop"> </td>
              </tr>
              <tr> 
                <td width="84" valign="top" class="newstop">homeID:</td>
                <td width="180" valign="top" class="newstop"><input name="homesid[<? echo $a ?>]" type="text"  value="<? echo $home_id[$a] ?>"  size="30" maxlength="30"></td>
              </tr>
              <tr> 
                <td class="newstop" valign="top">Titel:</td>
                <td  width="180" valign="top" class="newstop"><input name="titel[<? echo $a ?>]" type="text"  value="<? echo $home_title[$a] ?>"  size="30" maxlength="30"></td>
              </tr>
              <tr> 
                <td class="newstop" valign="top">Bild: breite:</td>
                <td width="180" valign="top" class="newstop"><input name="bildbreite[<? echo $a ?>]" type="text"  value="<? echo $home_breite[$a] ?>"  size="30" maxlength="30"></td>
              </tr>
              <tr> 
                <td class="newstop" valign="top">höhe:</td>
                <td  width="180" valign="top" class="newstop"><input name="bildhoehe[<? echo $a ?>]" type="text" value="<? echo $home_hoehe[$a] ?>"  size="30" maxlength="30"></td>
              </tr>
              <tr> 
                <td class="newstop" valign="top">bildname:</td>
                <td width="180" valign="top" class="newstop"><input name="bildname[<? echo $a ?>]" type="text"  value="<? echo $home_image[$a] ?>"  size="30" maxlength="30"></td>
              </tr>
              <tr align="center" bgcolor="#666666" > 
                <td height="5" colspan="7" valign="top"> <input type="checkbox" name="check[<? echo $a ?>]" value="<? echo $checkid[$a] ?>" onclick="this.form.checked();"> 
                </td>
              </tr>
              <?
$a++;
 }
?>
              <tr> 
                <td colspan="4" valign="top" class="newstop"><input type="submit" name="Submit2" value="Abschickenb"> 
                </td>
                <td colspan="3" valign="top" class="newstop"><input type="Checkbox" name="alle" onClick="AlleBoxen(this.form);" value="alle">Alle checkboxen anhaken.</td>
              </tr>
            </table>
        </fieldset>    </form>
</td>
        </tr>
       </table>
<?
}
?>
und hier das andere script(check.php) was die DB updaten soll:
<?
if($_POST['Submit2'] == "Abschickenb"){
for($i = 0; $i <= count($_REQUEST['check']); $i++)
{
  if(isset($_REQUEST['check'][$i]))
  {
$sql = "UPDATE newsart";
$sql .= "SET homeid = '".$_POST['homesid'][$i]."', ";
$sql .= "title = '".$_POST['titel'][$i]."', ";
$sql .= "description = '".$_POST['beschreibung'][$i]."', ";
$sql .= "image = '".$_POST['bildname'][$i]."', ";
$sql .= "hyperlink = '".$_POST['hyperlinks'][$i]."' , ";
$sql .= "breite = '".$_POST['bildbreite'][$i]."', ";
$sql .= "hoehe= '".$_POST['bildhoehe'][$i]."'";
$sql .= "WHERE id = '".$_REQUEST['check'][$i]."'";
mysql_db_query("xxxxxx", $sql);
 }
}
 
}
 ?>
</td></tr></table>
 
          
Kommentar