Update

nordi

Erfahrenes Mitglied
Erstmal allen ein schönes Osterfest.

So...jetzt zu meinem Problem :) Ich hab ein Gästebuch geschrieben und will da eine Kommentarfunktion einbauen. Ich übergebe von der gb.php die "id" vom Eintrag, den ich kommentieren will zur kommentar.php
Ich schätz mal, in der kommentar.php ist der Fehler...finde aber keinen.

PHP:
<?php include("config.inc.php"); ?>
<html>
<head>
<title>triogb.kommentarfunktion</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="stil.css" rel="stylesheet" type="text/css">
</head>

<body>
<table width="75%" border="0" cellspacing="0" cellpadding="0">
  <tr> 
    <td><strong>admin</strong>.kommentarfunktion</td>
  </tr>
  <tr> 
    <td>&nbsp;</td>
  </tr>
  <tr> 
    <td>Viel Spa&szlig; beim Kommentieren - <?php 
if($senden){

$verbindung = @mysql_connect("$dbhost","$dbuser","$dbpass");

if (!$verbindung) {
		echo "Verbindung zur Datenbank ist nicht möglich!\n";
		exit;
	}

mysql_select_db($dbtable,$verbindung);
	
$daten = "UPDATE $gb SET eintrag = '$komedit' WHERE id = '$id'";

$result = mysql_query($daten,$verbindung);

echo mysql_error();
echo "Erfolgreich kommentiert"; 
} ?></td>
  </tr>
  <tr> 
    <td>&nbsp;</td>
  </tr>
  <tr> 
    <td><form name="formular" method="post" action="kommentar.php">
        <textarea name="komedit" cols="53" rows="5"><?php
  $verbindung2 = @mysql_connect("$dbhost","$dbuser","$dbpass");

if (!$verbindung2) {
		echo "Verbindung zur Datenbank ist nicht möglich!\n";
		exit;
	}

mysql_select_db($dbtable,$verbindung2);
  $ergebnis = mysql_query("SELECT eintrag FROM $gb WHERE id = '$id'");
  while ($row = mysql_fetch_object($ergebnis))
    {
      echo $row->eintrag;
    }
  ?></textarea>
        <input type="submit" name="senden" value="update">
      </form></td>
  </tr>
  <tr> 
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>
    </td>
  </tr>
</table>
</body>
</html>

Seht ihr da irgendeinen Fehler?

Danke schon im vorraus und grüße aus Köln

marius
 
versuchs mal so:

da ich davon ausgehe, dass die id spalte vom typ integer ist (also nur zahlen!), solltest du folgendes ändern:
PHP:
$ergebnis = mysql_query("SELECT eintrag FROM $gb WHERE id = ".$_GET["id"]."");
später beim updaten musst du ja wissen, welche id bearbeitet werden soll. daher würd ich einfach im formular ein hidden-field anlegen, welches die id des ausgewählten datensatzes beinhaltet:
PHP:
<input type="hidden" name="id" value="<? echo $_GET["id"];?">
dann liest du dieses hidden field im update-befehl wieder aus damit die daten dann auch eingetragen werden:
PHP:
$daten = "UPDATE $gb SET eintrag = '$komedit' WHERE id = ".$_POST["id"]."";
ebenfalls sollte bei solchen fehler auch mal ein
PHP:
echo mysql_error();
helfen ;o)

grüße zurück aus köln *g
 
ich gehe mal davon aus, dass die datenbank nicht so heisst ;)
PHP:
mysql_select_db($dbtable,$verbindung);

sondern:

PHP:
mysql_select_db($dbtable);

[edit]
lustig finde ich nur, dass Du 2mal in der gleichen datei einen mysql_connect machst ..es genuegt einmal ein mysql_connect.
[/edit]
 
Zuletzt bearbeitet:
mh..hab alles gemacht, was ihr gesagt habt..jetzt wird eine Fehlermeldung in der Textbox angezeigt, wenn ich auf UPDATE klicke.

<br />
<b>Warning</b>: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in <b>C:\wampp2036\htdocs\home\html\trio\kommentar.php</b> on line <b>54</b><br />

Zeile 54 beinhaltet den Code mit while ($row blablabla

PHP:
<?php include("config.inc.php"); ?>
<html>
<head>
<title>triogb.kommentarfunktion</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="stil.css" rel="stylesheet" type="text/css">
</head>

<body>
<table width="75%" border="0" cellspacing="0" cellpadding="0">
  <tr> 
    <td><strong>admin</strong>.kommentarfunktion</td>
  </tr>
  <tr> 
    <td>&nbsp;</td>
  </tr>
  <tr> 
    <td>Viel Spa&szlig; beim Kommentieren - <?php 
if($senden){

$verbindung = @mysql_connect("$dbhost","$dbuser","$dbpass");

if (!$verbindung) {
		echo "Verbindung zur Datenbank ist nicht möglich!\n";
		exit;
	}

mysql_select_db($dbtable,$verbindung);
	
$daten = "UPDATE $gb SET eintrag = '$komedit' WHERE id = ".$_POST["id"]."";

$result = mysql_query($daten,$verbindung);

echo mysql_error();
echo "Erfolgreich kommentiert"; 
} ?></td>
  </tr>
  <tr> 
    <td>&nbsp;</td>
  </tr>
  <tr> 
    <td><form name="formular" method="post" action="kommentar.php">
	<input type="hidden" name="id" value="<? echo $_GET["id"];?>">
        <textarea name="komedit" cols="53" rows="5"><?php
  $verbindung2 = @mysql_connect("$dbhost","$dbuser","$dbpass");

if (!$verbindung2) {
		echo "Verbindung zur Datenbank ist nicht möglich!\n";
		exit;
	}

mysql_select_db($dbtable,$verbindung2);
  $ergebnis = mysql_query("SELECT eintrag FROM $gb WHERE id = ".$_GET["id"]."");
  while ($row = mysql_fetch_object($ergebnis))
    {
      echo $row->eintrag;
    }
  ?></textarea>
  <input type="submit" name="senden" value="update">
      </form></td>
  </tr>
  <tr> 
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>
    </td>
  </tr>
</table>
</body>
</html>

Chino: Woher genau kommst du?
 
wenn Du ein formular mit der Methode => POST uebergibst, dann solltest Du auch $_POST nutzen und nicht $_GET ..oder Du aenderst die Methode => GET ..wie auch immer ;)

Code:
<td><form name="formular" method="post" action="kommentar.php">
 
Zurück