Wie programmiert man richtig ???

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Wie programmiert man richtig ???

    Hi,

    ich muss nen Datenbankeintrag machen, ist ja kein Problem, hab mir einfach mal einen von Dreamweaver basteln lassen !!!

    Hier der Code
    PHP-Code:
    <?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 lexikon (id, gruppe, ueberschrift, text) VALUES (%s, %s, %s, %s)",
                           
    GetSQLValueString($HTTP_POST_VARS['id'], "int"),
                           
    GetSQLValueString($HTTP_POST_VARS['gruppe'], "int"),
                           
    GetSQLValueString($HTTP_POST_VARS['ueberschrift'], "text"),
                           
    GetSQLValueString($HTTP_POST_VARS['text'], "text"));

      
    mysql_select_db($database_db_connect$db_connect);
      
    $Result1 mysql_query($insertSQL$db_connect) or die(mysql_error());
    }
    ?>
    Ich mach das normalerweise so (kurzfassung):

    PHP-Code:
    $query  "INSERT INTO members (id,gruppe,ueberschrift,text) VALUES ('','$form_gruppe','$form_ueberschrift','$form_text')";
    $result MYSQL_QUERY($query,$db_connect); 
    Wo liegt der Unterschied ??? Kann mir das jemand erklären ???

  • #2
    Wenn ich das mal so kurz überfliege, würde ich sagen, das Dreamweaver das durch seine Abfrage vorher spezialisiert. Das heißt, der definiert die Feldtypen direkt mit. Wobei du das ja nicht unbedingt brauchst.

    Aber wenn ich mir das so ansehe, dann kann man das damit vergleichen als wenn Word ne HTML Seite erzeugt.

    PHP von Hand wurde ich bevorzugen!!!

    Kommentar

    Lädt...
    X