rony: MySQL Fehlermeldung

Hallo Gemeinde.

Nachdem ich ein Formular erstellt habe und auch eine Bindung zur Tabelle in der DB kommt eine Fehlermedung beim einfügen des Datensatzesn


You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1


Der Code der Datei sieht so aus:


<?php require_once('../Connections/inhalt1.php'); ?> <?php function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") {   $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

switch ($theType) {     case "text":       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";       break;     case "long":     case "int":       $theValue = ($theValue != "") ? intval($theValue) : "NULL";       break;     case "double":       $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";       break;     case "date":       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";       break;     case "defined":       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;       break;   }   return $theValue; }

$editFormAction = $HTTP_SERVER_VARS['PHP_SELF']; if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {   $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING']; }

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {   $insertSQL = sprintf("INSERT INTO stellen (stelle, ort, aufgaben, besonders, info, berater, email_berater, sonstiges) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",                        GetSQLValueString($HTTP_POST_VARS['stelle'], "text"),                        GetSQLValueString($HTTP_POST_VARS['ort'], "text"),                        GetSQLValueString($HTTP_POST_VARS['aufgaben'], "text"),                        GetSQLValueString($HTTP_POST_VARS['besonders'], "text"),                        GetSQLValueString($HTTP_POST_VARS['info'], "text"),                        GetSQLValueString($HTTP_POST_VARS['berater'], "text"),                        GetSQLValueString($HTTP_POST_VARS['email_berater'], "text"),                        GetSQLValueString($HTTP_POST_VARS['sonstiges'], "text"));

mysql_select_db($database_inhalt1, $inhalt1);   $Result1 = mysql_query($insertSQL, $inhalt1) or die(mysql_error());

$insertGoTo = "admin_offene_stellen.php";   if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";     $insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];   }   header(sprintf("Location: %s", $insertGoTo)); }

mysql_select_db($database_inhalt1, $inhalt1); $query_Recordset2 = "SELECT * FROM stellen ORDER BY id ASC"; $Recordset2 = mysql_query($query_Recordset2, $inhalt1) or die(mysql_error()); $row_Recordset2 = mysql_fetch_assoc($Recordset2); $totalRows_Recordset2 = mysql_num_rows($Recordset2); ?> <html> <head> <title>Formular</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head>

<body> <form method="post" name="form1" action="<?php echo $editFormAction; ?>">   <table align="center">     <tr valign="baseline">       <td nowrap align="right">Stelle:</td>       <td><input type="text" name="stelle" value="" size="32">       </td>     </tr>     <tr valign="baseline">       <td nowrap align="right">Ort:</td>       <td><input type="text" name="ort" value="" size="32">       </td>     </tr>     <tr valign="baseline">       <td nowrap align="right">Aufgaben:</td>       <td><input type="text" name="aufgaben" value="" size="32">       </td>     </tr>     <tr valign="baseline">       <td nowrap align="right">Besonders:</td>       <td><input type="text" name="besonders" value="" size="32">       </td>     </tr>     <tr valign="baseline">       <td nowrap align="right">Info:</td>       <td><input type="text" name="info" value="" size="32">       </td>     </tr>     <tr valign="baseline">       <td nowrap align="right">Berater:</td>       <td><input type="text" name="berater" value="" size="32">       </td>     </tr>     <tr valign="baseline">       <td nowrap align="right">Email_berater:</td>       <td><input type="text" name="email_berater" value="" size="32">       </td>     </tr>     <tr valign="baseline">       <td nowrap align="right">Sonstiges:</td>       <td><input type="text" name="sonstiges" value="" size="32">       </td>     </tr>     <tr valign="baseline">       <td nowrap align="right"> </td>       <td><input type="submit" value="Datensatz einfügen">       </td>     </tr>   </table>   <input type="hidden" name="MM_insert" value="form1"> </form> <p> </p> </body> </html> <?php mysql_free_result($Recordset2); ?> <?php require_once('../Connections/inhalt1.php'); ?> <?php function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") {   $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

switch ($theType) {     case "text":       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";       break;     case "long":     case "int":       $theValue = ($theValue != "") ? intval($theValue) : "NULL";       break;     case "double":       $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";       break;     case "date":       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";       break;     case "defined":       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;       break;   }   return $theValue; }

$editFormAction = $HTTP_SERVER_VARS['PHP_SELF']; if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {   $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING']; }

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {   $insertSQL = sprintf("INSERT INTO stellen (stelle, ort, aufgaben, besonders, info, berater, email_berater, sonstiges) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",                        GetSQLValueString($HTTP_POST_VARS['stelle'], "text"),                        GetSQLValueString($HTTP_POST_VARS['ort'], "text"),                        GetSQLValueString($HTTP_POST_VARS['aufgaben'], "text"),                        GetSQLValueString($HTTP_POST_VARS['besonders'], "text"),                        GetSQLValueString($HTTP_POST_VARS['info'], "text"),                        GetSQLValueString($HTTP_POST_VARS['berater'], "text"),                        GetSQLValueString($HTTP_POST_VARS['email_berater'], "text"),                        GetSQLValueString($HTTP_POST_VARS['sonstiges'], "text"));

mysql_select_db($database_inhalt1, $inhalt1);   $Result1 = mysql_query($insertSQL, $inhalt1) or die(mysql_error());

$insertGoTo = "admin_offene_stellen.php";   if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";     $insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];   }   header(sprintf("Location: %s", $insertGoTo)); }

mysql_select_db($database_inhalt1, $inhalt1); $query_Recordset2 = "SELECT * FROM stellen ORDER BY id ASC"; $Recordset2 = mysql_query($query_Recordset2, $inhalt1) or die(mysql_error()); $row_Recordset2 = mysql_fetch_assoc($Recordset2); $totalRows_Recordset2 = mysql_num_rows($Recordset2); ?> <html> <head> <title>Formular</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head>

<body> <form method="post" name="form1" action="<?php echo $editFormAction; ?>">   <table align="center">     <tr valign="baseline">       <td nowrap align="right">Stelle:</td>       <td><input type="text" name="stelle" value="" size="32">       </td>     </tr>     <tr valign="baseline">       <td nowrap align="right">Ort:</td>       <td><input type="text" name="ort" value="" size="32">       </td>     </tr>     <tr valign="baseline">       <td nowrap align="right">Aufgaben:</td>       <td><input type="text" name="aufgaben" value="" size="32">       </td>     </tr>     <tr valign="baseline">       <td nowrap align="right">Besonders:</td>       <td><input type="text" name="besonders" value="" size="32">       </td>     </tr>     <tr valign="baseline">       <td nowrap align="right">Info:</td>       <td><input type="text" name="info" value="" size="32">       </td>     </tr>     <tr valign="baseline">       <td nowrap align="right">Berater:</td>       <td><input type="text" name="berater" value="" size="32">       </td>     </tr>     <tr valign="baseline">       <td nowrap align="right">Email_berater:</td>       <td><input type="text" name="email_berater" value="" size="32">       </td>     </tr>     <tr valign="baseline">       <td nowrap align="right">Sonstiges:</td>       <td><input type="text" name="sonstiges" value="" size="32">       </td>     </tr>     <tr valign="baseline">       <td nowrap align="right"> </td>       <td><input type="submit" value="Datensatz einfügen">       </td>     </tr>   </table>   <input type="hidden" name="MM_insert" value="form1"> </form> <p> </p> </body> </html> <?php mysql_free_result($Recordset2); ?>


Komm da nicht weiter ... Herzlichen Dank für Eure Mühe. MfG rony

  1. Ups , zwei mal gedrückt...
    tut mir echt leid. sorry

    so sollte es aussehen.

    _________________________________________________________

    <?php require_once('../Connections/inhalt1.php'); ?>
    <?php
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {
      $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

    switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }

    $editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
    if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
      $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
    }

    if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {
      $insertSQL = sprintf("INSERT INTO stellen (stelle, ort, aufgaben, besonders, info, berater, email_berater, sonstiges) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
                           GetSQLValueString($HTTP_POST_VARS['stelle'], "text"),
                           GetSQLValueString($HTTP_POST_VARS['ort'], "text"),
                           GetSQLValueString($HTTP_POST_VARS['aufgaben'], "text"),
                           GetSQLValueString($HTTP_POST_VARS['besonders'], "text"),
                           GetSQLValueString($HTTP_POST_VARS['info'], "text"),
                           GetSQLValueString($HTTP_POST_VARS['berater'], "text"),
                           GetSQLValueString($HTTP_POST_VARS['email_berater'], "text"),
                           GetSQLValueString($HTTP_POST_VARS['sonstiges'], "text"));

    mysql_select_db($database_inhalt1, $inhalt1);
      $Result1 = mysql_query($insertSQL, $inhalt1) or die(mysql_error());

    $insertGoTo = "admin_offene_stellen.php";
      if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
        $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
        $insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
      }
      header(sprintf("Location: %s", $insertGoTo));
    }

    mysql_select_db($database_inhalt1, $inhalt1);
    $query_Recordset2 = "SELECT * FROM stellen ORDER BY id ASC";
    $Recordset2 = mysql_query($query_Recordset2, $inhalt1) or die(mysql_error());
    $row_Recordset2 = mysql_fetch_assoc($Recordset2);
    $totalRows_Recordset2 = mysql_num_rows($Recordset2);
    ?>
    <html>
    <head>
    <title>Formular</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <form method="post" name="form1" action="<?php echo $editFormAction; ?>">
      <table align="center">
        <tr valign="baseline">
          <td nowrap align="right">Stelle:</td>
          <td><input type="text" name="stelle" value="" size="32">
          </td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">Ort:</td>
          <td><input type="text" name="ort" value="" size="32">
          </td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">Aufgaben:</td>
          <td><input type="text" name="aufgaben" value="" size="32">
          </td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">Besonders:</td>
          <td><input type="text" name="besonders" value="" size="32">
          </td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">Info:</td>
          <td><input type="text" name="info" value="" size="32">
          </td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">Berater:</td>
          <td><input type="text" name="berater" value="" size="32">
          </td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">Email_berater:</td>
          <td><input type="text" name="email_berater" value="" size="32">
          </td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">Sonstiges:</td>
          <td><input type="text" name="sonstiges" value="" size="32">
          </td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right"> </td>
          <td><input type="submit" value="Datensatz einfügen">
          </td>
        </tr>
      </table>
      <input type="hidden" name="MM_insert" value="form1">
    </form>
    <p> </p>
    </body>
    </html>
    <?php
    mysql_free_result($Recordset2);
    ?>

  2. hi,

    Nachdem ich ein Formular erstellt habe und auch eine Bindung zur Tabelle in der DB kommt eine Fehlermedung beim einfügen des Datensatzesn
    You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

    hast du dir den query-string, nachdem du ihn mit sprintf zusammengesetzt hast, mal mit echo zur kontrolle ausgeben lassen - ob da auch wirklich alle werte so gefüllt sind, wie du dir das vorstellst?

    gruss,
    wahsaga