PHP-Code:
echo "<input name=".$username." maxlength=20 size=20 readonly>";
echo "<a href=script.php?action=delete&id=id_vom_eintrag>delete</a>";
if ($_GET['action'] == "delete") {
$sql = "DELETE FROM tabelle WHERE id = '$_GET[id]'";
$result = mysql_query($sql,$conn);
}
<?php
// ausgabe.php
?>
<html>
<body>
<table width="90%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="10%" bgcolor="cecece"><font face="Arial" color="Red">UserID</font></td>
<td width="70%" bgcolor="cecece"><font face="Arial" color="red">User Name</font></td>
<td width="10%" bgcolor="cecece"><font face="Arial" color="Red">Löschen</font></td>
<td width="10%" bgcolor="cecece"><font face="Arial" color="Red">Ändern</font></td>
</tr>
<?
// User aus der Datenbank holen
$res = mysql_query("SELECT * FROM tabelle")or die(mysql_error());
while($row=mysql_fetch_array($res))
{
// Farbwechsler
if (($counter++ % 2) != 0)
{
$bg="#999999";
}
else
{
$bg="#CCCCCC";
}
echo'<tr>
<td bgcolor="$bg"><font face="Arial" color="black">$row[userID]</font></td>
<td bgcolor="$bg"><font face="Arial" color="black">$row[userName]</font></td>
<td bgcolor="$bg"><font face="Arial" color="black"><a href="tuwas.php?action=loeschen&id=$row[userID]">User Löschen</a></font></td>
<td bgcolor="$bg"><font face="Arial" color="black"><a href="tuwas.php?action=aendern&id=$row[userID]">User ändern</a></font></td>
</tr>';
}
?>
</table>
</body>
</html>
<?php
//tuwas.php
?>
<html>
<body>
<?php
// hier wird der User gelöscht
if($action== "loeschen")
{
$res = mysql_query("DELETE FROM tabelle WHERE userID='$id'")or die(mysql_error());
$num = mysql_affected_rows();
if ($num>0)
{
echo '<font face="Arial" color="red"><b>Der User wurde gelöscht.</b></font>';
}
}
// hier wird der User geändert
if($acion == "aendern")
{
$res = mysql_query("SELECT * FROM tabelle WHERE userID='$id'")or die(mysql_error());
while($row = mysql_fetch_array($res))
{
echo'<form action="tuwas.php?action=jetzt" method="post">
<input type="hidden" name="id" value="$row[userID]">
<table width="50%" border="0">
<tr>
<td width="20%">User Name:</td>
<td width="80%">$row[userName]</td>
</tr>
<tr>
<td width="20%">User eMail:</td>
<td width="80%"><input type="text" name="eMail" value="$row[usereMail]"></td>
</tr>
<tr>
<td colspan="2"><center><input type="submit" value="User ändern"></center></td>
</tr>
</table>
</form>';
}
}
// hier wird der User in der Datenbank geändert
if($action=="jetzt")
{
$res = mysql_query("UPDATE tabelle SET usereMail='$eMail' WHERE userID='$id'")or die(mysql_error());
$num = mysql_affected_rows();
if ($num>0)
{
echo '<font face="Arial" color="red"><b>Der User wurde geändert.</b></font>';
}
}
?>
</body>
</html>
Kommentar