Syntaxprobleme PHP / MySQL

Hallo,

ich möchte einfach nur 4 Daten in eine Tabelle einbauen, aber leider scheiters bei mir beim eintragen. er macht einfach nichts !?

könnt ihr mir dazu was sagen? :confused:

PHP:
<?
include 'inc/config.php';    // Konfigurationsdatei laden
        @mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS) OR die(mysql_error());    
        mysql_select_db(MYSQL_DATABASE) OR die(mysql_error());
function eintragen ($titel, $text, $datum, $author)
{
if (mysql_query("INSERT INTO news (titel, text, datum, author) VALUES ('$titel','$text', Now(), 'author')")) 
die('Fehler ! Der SQL-Befehl ist Falsch'); 
}

?>
<form name="form1" method="post" action="eintragen">
  <table width="500" border="0">
    <tr>
      <td valign="top">Titel</td>
      <td valign="top"> 
        <input type="text" name="titel">
      </td>
    </tr>
    <tr>
      <td valign="top">Text </td>
      <td valign="top"> 
        <textarea name="text" wrap="VIRTUAL" cols="50" rows="10"></textarea>
      </td>
    </tr>
    <tr>
      <td valign="top">Author </td>
      <td valign="top"> 
        <input type="text" name="author">
      </td>
    </tr>
  </table>
  <input type="submit" name="eintragen" value="Eintragen">
  <br>
  <br>
</form>
 
Hi,

ich weiß zwar nicht genau was daran falsch ist aber versuch doch mal folgendes, übergebe im Formular ein hidden field:
<input type="hidden" name="step" value="2">

und schreib dann statt Deiner Funktion einfach:

Code:
if ($step == 2 ) {
mysql_query("INSERT INTO ...Dein Zeug");
}

Gruß
Bazi
 
PHP:
<?
function eintragen ($titel, $text, $datum, $author)
{
if (mysql_query("INSERT INTO news (titel, text, datum, author) VALUES ('$titel','$text', Now(), 'author')")) 
die('Fehler ! Der SQL-Befehl ist Falsch'); 
}
?>

Du schreibst hier alles in eine Funktion, welche allerdings nie aufgerufen wird.
 
Probier mal Folgendes:
PHP:
<?php

	include 'inc/config.php';    // Konfigurationsdatei laden
	@mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS) OR die(mysql_error());    
	mysql_select_db(MYSQL_DATABASE) OR die(mysql_error());


	if( isset($_post['eintragen']) ) {
		$query = "
			INSERT INTO
			        `news`
			  SET
			        `titel`  = '".mysql_real_escape_string($_POST['titel'])."',
			        `text`   = '".mysql_real_escape_strinf($_POST['text'])."',
			        `datum`  = NOW(),
			        `author` = '",mysql_real_escape_string($_POST['author'])."'
			";
		mysql_query($query) or die('<p>Fehler beim Versenden einer Abfrage:</p><pre>'.htmlspecialchars($query).'<pre>');
	}

?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
	…
</form>
 
Zurück