Das Formular ist etwas, das Geändere sehr heftig verändert.
Die <input />s für ID sind versteckt. Die Namen um [] erweitert, damit sie als Arrays übertragen werden.
Über $_POST['id'] wird per foreach iteriert um an Indexschlüssel zu kommen.
Jeder Datensatz wird per UPDATE behandelt, nicht nur geänderte. MySQL wird selbst checken, ob sich da etwas geändert hat.
PHP-Code:
<form method="post" action="aendern.php">
<?php
include("db.php");
$abfrage = "SELECT * FROM rep_pwm ORDER BY id DESC";
$ergebnis = mysql_query($abfrage) or die( mysql_error() );
while($row = mysql_fetch_array($ergebnis))
{
$id = $row["id"];
$clan = $row["clan"];
$bild = $row["bild"];
print '<input type="hidden" name="id[]" width="20" value="'.$id.'">';
print 'Clan: <input type="text" name="clan[]" width="20" value="'.$clan.'">';
print 'Bild: <input type="text" name="bild[]" width="20" value="'.$bild.'">
';
}
?>
<input type="submit" name="send" value="Edit">
PHP-Code:
<?php
include("db.php");
foreach ($_POST['id'] as $key => $id) {
print 'Aktualisiere: '.$_POST['clan'][$key].'
'."\n";
$insert = "
UPDATE rep_pwm
SET clan = '".$_POST['clan'][$key]."',
bild = '".$_POST['bild'][$key]."'
WHERE id = ".$id."
";
$res = mysql_query ($insert);
if (!$res) {
print 'Fehler: '.mysql_error().'
'."\n";
} else {
if (mysql_affected_rows == 0) {
print 'Fehler: ???
'."\n";
} else {
print 'Erfolgreich
'."\n";
}
}
}
?>