Wo ist der Fehler? (MySQL)

Voggi

Gesperrt
Hallo,
ich möchte was aus einem Formular in eine MySQL Datenbank einfügen.
PHP:
include("./data/connect.inc.php");
$sql_insert = 'INSERT INTO `guestbook` ( `id` , `name` , `email` , `comment` ) '
        . ' VALUES ( \'\', $name, $email, $comment);'
        . ' '; 
mysql_query($sql_insert) or die (mysql_error());
ich find einfach den Fehler nicht.
 
Setz die Werte in single-quotes
PHP:
 include("./data/connect.inc.php"); 
$sql_insert = 'INSERT INTO `guestbook` ( `id` , `name` , `email` , `comment` ) ' 
        . ' VALUES ( '', '$name', '$email', '$comment');' 
        . ' '; 
mysql_query($sql_insert) or die (mysql_error());
 
Dein Vorschlag wird auch nicht funktionieren, hans_schmid.

Versuch' mal foldendes:
PHP:
<?php
  include("./data/connect.inc.php"); 
  $query = "
	INSERT INTO
	        `guestbook`
	  SET
	        `name` = '".mysql_escape_string($name)."',
	        `email` = '".mysql_escape_string($email)."',
	        `comment` = '".myslq_escape_string($comment)."'
	";
  
  if( !mysql_query($query) ) {
    echo '<p><strong>MySQL Error <tt>'.mysql_errno().'</tt>:</strong> '.htmlspecialchars(mysql_error()).'<pre>'.$query.'</pre></p>';
    exit;
  }
  [...]
?>
 
ach ja, hab ich vergessen
wenn ich es so verwende, wie ich es haben , dann sagt er:


You have an error in your SQL syntax near '; ' at line 1
 
Probiers mal so:
PHP:
include("./data/connect.inc.php");
$sql_insert = 'INSERT INTO `guestbook` ( `id` , `name` , `email` , `comment` ) VALUES ( '', $name, $email, $comment)';
mysql_query($sql_insert) or die (mysql_error());


Der Doc!
 
Zurück