Datensätze ändern/löschen

tadlos

Mitglied
Hallo,

ich arbeite in letzter Zeit an einer Homepage.
Soweit ist auch alles fertig, jetzt will ich nur noch ein kleinen Adminbereich erstellen,
wo Gästebucheinträge usw bearbeitet bzw. gelöscht werden können.

Leider hänge ich seit Tagen an einem Problem fest, ich kann die Datensätze zwar in einem Formular ausgeben, nur leider kann ich nichts bearbeitet.

Ich hoffe ihr könnt mir da weiter helfen..

Hier ist der Inhalt von der admin.php:

PHP:
<?php
    
    include("functions.inc.php");
    
    mysqlconnect();
    
    // Abfrage nach Aufruf
    if ( isset( $_REQUEST["do"] ) && $_REQUEST["do"] == "kill" )
    {
	// Ein Datensatz soll gelöscht werden
	$id	=	$_REQUEST["form_id"];
	
	$query	=	"DELETE FROM sb_gaestebuch WHERE id=" . $id;
	
	$result =	mysql_query( $query );
	
	if ( ! $result )
	{
	    die("Konnte den Datensatz nicht l&ouml;schen: " . mysql_error() );
	}
	
	header("Location: index.php");
	die;
    }
    
     if ( isset( $_REQUEST["do"] ) && $_REQUEST["do"] == "change" )
    {
	// Ein Datensatz soll gelöscht werden
	$id	=	$_REQUEST["form_id"];
	
	$query	=	"UPDATE sb_gaestebuch SET Titel='" . $_REQUEST["form_titel"] . "', Text='" . $_REQUEST["form_text"] . "' WHERE id=" . $id;
	
	$result=	mysql_query( $query );
	
	if ( ! $result )
	{
	    die("Konnte den Datensatz nicht &auml;ndern: " . mysql_error() );
	}
	
	header("Location: main.php");
	die;
	
    }

   

    $query	=	"SELECT * FROM sb_gaestebuch ORDER BY id DESC";
    
    $result	=	mysql_query( $query );
    
    if ( ! $result )
    {
	    die("Konnte die Datens&auml;tze nicht auslesen");
    }

    $anzahl	=	mysql_num_rows( $result );
    

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<meta name="generator" content="Adobe GoLive 6">
		<title>Willkommen bei Adobe GoLive 6</title>
		<style type="text/css" media="screen"><!--
body { font-family: Arial, Helvetica, Geneva, Swiss, SunSans-Regular }
a { color: red; text-decoration: none }
a:hover { text-decoration: underline }
.fliesstext { font-size: small }
.titel { font-weight: bold }
.beschr_hell { color: #ccc; font-weight: bold }
.maintitle  { color: gray; font-weight: bold; font-size: large }
--></style>
	</head>

	<body bgcolor="#ffffff">
		<table width="545" border="0" cellspacing="0" cellpadding="2">
			<tr>
				<td colspan="3" align="center" width="541">
					<p class="maintitle">PHP-&Uuml;bungs-G&auml;stebuch</p>
				</td>
			</tr>
			<tr>
				<td width="45">&nbsp;</td>
				<td width="388">&nbsp;</td>
				<td width="100">&nbsp;</td>
			</tr>
			<tr>
				<td width="45"><a href="(EmptyReference!)">Home</a></td>
				<td align="center" width="388"><a href="(EmptyReference!)">&nbsp;</a></td>
				<td width="100"><a href="(EmptyReference!)">&nbsp;</a></td>
			</tr>
		</table>
		<p></p>
		<table width="550" border="0" cellspacing="0" cellpadding="2">
		<?php
		    // Schleife zum Ausgeben der einzelnen Datensätze in Tabellen-Reihen
		    for ( $i=1; $i <= $anzahl; $i++)
		    {
			$datensatz	=	mysql_fetch_array( $result );
					
		?>
		<form action="<?php echo $_REQUEST["SELF_PHP"]; ?>" method="POST">
			<tr>
				<td class="beschr_hell" align="left" valign="top" bgcolor="#666666" width="80">Datum</td>
				<td class="beschr_hell" align="left" valign="top" bgcolor="#666666" width="363">&nbsp;</td>
				<td class="beschr_hell" align="left" valign="top" bgcolor="#666666" width="95">Autor</td>
			</tr>
			<tr>
				<td align="left" valign="top" bgcolor="#cccccc" width="80"><?php echo $datensatz['datum']; ?></td>
				<td align="left" valign="top" bgcolor="#cccccc" width="363">&nbsp;</td>
				<td align="left" valign="top" bgcolor="#cccccc" width="95"><a href="mailto:test@email.de"><?php echo $datensatz["name"]; ?></a></td>
			</tr>
			<tr>
				<td align="left" valign="top" bgcolor="#999999" width="80">&nbsp;</td>
				<td align="left" valign="top" bgcolor="#999999" width="363">&nbsp;</td>
				<td align="left" valign="top" bgcolor="#999999" width="95">&nbsp;</td>
			</tr>
			<tr>
				<td class="beschr_hell" align="left" valign="top" bgcolor="#999999" width="80">Titel</td>
				<td colspan="2" align="left" valign="top" bgcolor="#cccccc" width="462">
					<p class="titel"><input type="text" name="form_titel" size="59" border="0" value="<?php echo $datensatz['titel']; ?>" ></p>
				</td>
			</tr>
			<tr>
				<td align="left" valign="top" bgcolor="#999999" width="80">&nbsp;</td>
				<td align="left" valign="top" bgcolor="#cccccc" width="363">&nbsp;</td>
				<td align="left" valign="top" bgcolor="#cccccc" width="95">&nbsp;</td>
			</tr>
			<tr>
				<td class="beschr_hell" align="left" valign="top" bgcolor="#999999" width="80">Text</td>
				<td colspan="2" align="left" valign="top" bgcolor="#cccccc" width="462">
					<p class="fliesstext"><textarea name="form_text" rows="8" cols="57"><?php echo $datensatz["beitrag"]; ?></textarea></p>
				</td>
			</tr>
			<tr>
				<td align="left" valign="top" bgcolor="#999999" width="80">&nbsp;</td>
				<td align="left" valign="top" bgcolor="#cccccc" width="363">&nbsp;</td>
				<td align="left" valign="top" bgcolor="#cccccc" width="95">&nbsp;</td>
			</tr>
			<tr>
				<td align="left" valign="top" bgcolor="#999999" width="80">&nbsp;</td>
				<td align="left" valign="top" bgcolor="#cccccc" width="363"><input type="radio" name="do" value="change" checked border="0"> &auml;ndern <input type="radio" name="do" value="kill" border="0"> l&ouml;schen</td>
				<td align="left" valign="top" bgcolor="#cccccc" width="95">&nbsp;</td>
			</tr>
			<tr>
				<td align="left" valign="top" bgcolor="#999999" width="80">&nbsp;</td>
				<td align="left" valign="top" bgcolor="#cccccc" width="363">&nbsp;</td>
				<td align="left" valign="top" bgcolor="#cccccc" width="95">&nbsp;</td>
			</tr>
			<tr>
				<td align="left" valign="top" bgcolor="#999999" width="80"><input type="hidden" name="form_id" value="<?php echo $datensatz['id']; ?>"></td>
				<td align="left" valign="top" bgcolor="#cccccc" width="363"><input type="submit" name="submit" value="&Auml;ndern" border="0"></td>
				<td align="left" valign="top" bgcolor="#cccccc" width="95">&nbsp;</td>
			</tr>
			<tr>
				<td align="left" valign="top" bgcolor="#999999" width="80">&nbsp;</td>
				<td align="left" valign="top" bgcolor="#cccccc" width="363">&nbsp;</td>
				<td align="left" valign="top" bgcolor="#cccccc" width="95">&nbsp;</td>
			</tr>
			<tr>
				<td align="left" valign="top" width="80">&nbsp;</td>
				<td align="left" valign="top" width="363">&nbsp;</td>
				<td align="left" valign="top" width="95">&nbsp;</td>
			</tr>
			</form>
			<?php
			    }
			?>
		    
			<tr>
				<td align="left" valign="top" bgcolor="#999999" width="80"><a href="(EmptyReference!)">zur&uuml;ck</a></td>
				<td align="center" valign="top" bgcolor="#cccccc" width="363">Seite 1 von 10</td>
				<td align="right" valign="top" bgcolor="#cccccc" width="95"><a href="(EmptyReference!)">weiter</a></td>
			</tr>
		</table>
		<p></p>
	</body>

</html>

Falls das wichtig ist..
Name der DB db703373
Tabellenname sb_gastebuch
Spalten id name titel beitrag datum

Gruß Stefan
 
Ähm.
PHP:
if(count($infos)>1)
{echo "mehr Antworten";}
Kommt eine Fehlermeldung? Welche?
Bleibt die Seite weiß? Error ausgeben lassen?!
Passiert garnix? Wie? Was? Wo?

mfg chmee

Nachtrag Ich gehe einfach davon aus, dass Du das Löschen/Verändern nicht nur über eine GET-Variable zulässt. Sobald Jemand die GET kennt, ist die DB leer. Und auch SQL-Injections sind bei der simplen Übergabe nur eine Frage der Zeit.

Stell Dir vor ich setze in der GET-Variable form_id nicht nur die id sondern
Code:
1' or 1=1
// oder
1'; DROP TABLE sb_gastebuch
 
Zuletzt bearbeitet:
Nachdem ich auf Ändern gedrückt habe, kommt eine neue Seite.
Mit der Fehlermeldung "Objekt nicht gefunden"..

Das interessante steht oben in der Adressleiste:"http://localhost/laju/%3Cbr%20/%3E%3Cb%3ENotice%3C/b%3E:%20%20Undefined%20index:%20SELF_PHP%20in%20%3Cb%3EC:%5Cxampp%5Chtdocs%5Claju%5Cadmin.php%3C/b%3E%20on%20line%20%3Cb%3E106%3C/b%3E%3Cbr%20/%3E"
 
Code:
http://localhost/laju/<br /><b>Notice</b>: 
Undefined index: SELF_PHP in <b>C:\xampp\htdocs\laju\admin.php</b> on line <b>106</b><br />"
URLDecode! http://www.albionresearch.com/misc/urlencode.php

Scheinbar ist also in admin.php in Zeile 106 die Variable SELF_PHP aufgerufen, welche nicht existiert?

Es heisst wohl $PHP_SELF bzw.
PHP:
echo $_SERVER['PHP_SELF'];
Abgesehen davon, einfach mal per
PHP:
phpinfo();
nachschauen, ob sie existiert. Sollte ganz unten stehen.
http://www.php.net/manual/de/language.variables.superglobals.php

mfg chmee
 
Du sollst $_REQUEST nicht verwenden, statt dessen $_POST oder $_GET.

Um dein Problem zu lösen solltest du die Form-Ziel-Adresse so anlegen:

PHP:
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="POST">
 
Ok ich habe das jetzt in $PHP_SELF geändert.
Leider geht das immer noch nicht.

Beim XAMPP Server ist die Funktion aktiv.

_SERVER["PHP_SELF"] /laju/php.php
 
Also die Verbindung der DB ist ja ok.

So wie ich das sehe liegt der Fehler irgendwo im Formular..
Es ist auch egal ob ich jetzt ändern auswähle oder löschen.. Der Fehler bleibt gleich.. Hmmm...
 
Sauber Jungs.. Der Tipp von Saftmeister hat geklappt.. Ich bedanke mich.. Bei Facebook würde ich auf "Gefällt mir" drücken ;)
 
Zurück