+ Antworten
Ergebnis 1 bis 8 von 8

Thema: Kontaktformular mit Upload in MySql

  1. #1
    TP-Newbie schamane69 macht alles soweit korrekt
    Registriert seit
    Mar 2010
    Beiträge
    3

    Kontaktformular mit Upload in MySql

    Hallo!

    Ich möchte per einem PHP Formular neben Daten wie Name, Datum, ip usw. auch wie drei Upload Pfade in einer MySql-Datenbank speichern.

    Die Speicherung der Daten von Name und Vornamen und die ID vergabe klappt.

    Probleme habe ich mit der Übermittlung der IP-Adresse sowie des Datums.
    Wie bekomme ich den Upload und die Speicherung des Datenpfades hin.

    Zum Schluss sollte ich noch eine Email, mit der Information erhalten das neuer Eintrag vorhanden ist.

    Vielleicht klappt es ja mit eurer Hilfe.

    Datenbank
    PHP-Code:
    -- phpMyAdmin SQL Dump
    -- version 3.2.0.1
    -- http://www.phpmyadmin.net
    --
    -- 
    Hostlocalhost
    -- Erstellungszeit07. März 2010 um 15:37
    -- Server Version5.1.37
    -- PHP-Version5.3.0

    SET SQL_MODE
    ="NO_AUTO_VALUE_ON_ZERO";

    --
    -- 
    Datenbank: `test`
    --

    -- --------------------------------------------------------

    --
    -- 
    Tabellenstruktur für Tabelle `test`
    --

    CREATE TABLE IF NOT EXISTS `test` (
      `
    idint(11NOT NULL AUTO_INCREMENT,
      `
    namevarchar(25NOT NULL,
      `
    vornamevarchar(25NOT NULL,
      `
    datumvarchar(25NOT NULL,
      `
    ipvarchar(25NOT NULL,
      `
    bildvarchar(100NOT NULL,
      `
    upload1varchar(100NOT NULL,
      `
    upload2varchar(100NOT NULL,
      
    PRIMARY KEY (`id`)
    ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=;

    --
    -- 
    Daten für Tabelle `test`
    -- 
    Formular
    PHP-Code:
    <?php
    if (!function_exists("GetSQLValueString")) {
    function 
    GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
    {
      if (
    PHP_VERSION 6) {
        
    $theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
      }

      
    $theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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 $_SERVER['PHP_SELF'];
    if (isset(
    $_SERVER['QUERY_STRING'])) {
      
    $editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
    }

    if ((isset(
    $_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
      
    $insertSQL sprintf("INSERT INTO test (id, name, vorname, datum, ip, bild, upload1, upload2) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
                           
    GetSQLValueString($_POST['id'], "int"),
                           
    GetSQLValueString($_POST['name'], "text"),
                           
    GetSQLValueString($_POST['vorname'], "text"),
                           
    GetSQLValueString($_POST['datum'], "text"),
                           
    GetSQLValueString($_POST['ip'], "text"),
                           
    GetSQLValueString($_POST['bild'], "text"),
                           
    GetSQLValueString($_POST['upload1'], "text"),
                           
    GetSQLValueString($_POST['upload2'], "text"));

      
    mysql_select_db($database_test$test);
      
    $Result1 mysql_query($insertSQL$test) or die(mysql_error());
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Unbenanntes Dokument</title>
    </head>

    <body>
    <form action="<?php echo $editFormAction?>" method="post" enctype="multipart/form-data" name="form1" id="form1">
            <table align="center">
                    <tr valign="baseline">
                            <td nowrap="nowrap" align="right">Name:</td>
                            <td><input type="text" name="name" value="" size="32" /></td>
                    </tr>
                    <tr valign="baseline">
                            <td nowrap="nowrap" align="right">Vorname:</td>
                            <td><input type="text" name="vorname" value="" size="32" /></td>
                    </tr>
                    <tr valign="baseline">
                            <td nowrap="nowrap" align="right">Bild:</td>
                            <td>
                            <input type="file" name="bild" id="fileField" /></td>
                    </tr>
                    <tr valign="baseline">
                            <td nowrap="nowrap" align="right">Upload1:</td>
                            <td><label>
                                            <input type="file" name="upload1" id="fileField2" />
                            </label></td>
                    </tr>
                    <tr valign="baseline">
                            <td nowrap="nowrap" align="right">Upload2:</td>
                            <td><input type="file" name="upload2" id="fileField3" /></td>
                    </tr>
                    <tr valign="baseline">
                            <td nowrap="nowrap" align="right">&nbsp;</td>
                            <td><input type="submit" value="Datensatz einf&uuml;gen" /></td>
                    </tr>
            </table>
            <input type="hidden" name="id" value="" />
            <input type="hidden" name="datum" value="<?=time(); ?>" />
            <input type="hidden" name="ip" value="<?=$_SERVER["REMOTE_ADDR"];?>" />
            <input type="hidden" name="MM_insert" value="form1" />
    </form>
    <p>&nbsp;</p>
    </body>
    </html>
    Verbindung zur DB
    PHP-Code:
    <?php
    # FileName="Connection_php_mysql.htm"
    # Type="MYSQL"
    # HTTP="true"
    $hostname_test "localhost";
    $database_test "test";
    $username_test "root";
    $password_test "root";
    $test mysql_pconnect($hostname_test$username_test$password_test) or trigger_error(mysql_error(),E_USER_ERROR); 
    ?>

  2. #2
    TP-Supporter chorn bringt sich richtig ein Avatar von chorn
    Registriert seit
    Apr 2008
    Ort
    Verden
    Beiträge
    370
    Lass dir $insertSQL doch mal per "echo" ausgeben und guck nach was da drin steht. Was kommt in der Datenbank an? Dateiuploads stehen in _FILES, nicht _POST. Und Mails kannst du mit mail() versenden.

    http://php.net/manual/en/features.file-upload.php
    http://php.net/mail

    Zitat Zitat von schamane69 Beitrag anzeigen
    Probleme habe ich mit
    ist keine ausreichende Problembeschreibung.

  3. #3
    TP-Newbie schamane69 macht alles soweit korrekt
    Registriert seit
    Mar 2010
    Beiträge
    3
    Das Problem mit den Datei Upload habe gelöst.

    PHP-Code:
    <?php require_once('Connections/test.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function 
    GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
    {
      if (
    PHP_VERSION 6) {
        
    $theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
      }

      
    $theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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 $_SERVER['PHP_SELF'];
    if (isset(
    $_SERVER['QUERY_STRING'])) {
      
    $editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
    }

    if ((isset(
    $_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
      
    $insertSQL sprintf("INSERT INTO test (id, name, vorname, datum, ip, bild, upload1, upload2) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
                           
    GetSQLValueString($_POST['id'], "int"),
                           
    GetSQLValueString($_POST['name'], "text"),
                           
    GetSQLValueString($_POST['vorname'], "text"),
                           
    GetSQLValueString($_POST['datum'], "text"),
                           
    GetSQLValueString($_POST['ip'], "text"),
                           
    GetSQLValueString($_FILES['bild']['name'], "text"),
                           
    GetSQLValueString($_FILES['upload1']['name'], "text"),
                           
    GetSQLValueString($_FILES['upload2']['name'], "text"));

      
    mysql_select_db($database_test$test);
      
    $Result1 mysql_query($insertSQL$test) or die(mysql_error());
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Unbenanntes Dokument</title>
    </head>

    <body>
    <form action="<?php echo $editFormAction?>" method="post" enctype="multipart/form-data" name="form1" id="form1">
            <table align="center">
                    <tr valign="baseline">
                            <td nowrap="nowrap" align="right">Name:</td>
                            <td><input type="text" name="name" value="" size="32" /></td>
                    </tr>
                    <tr valign="baseline">
                            <td nowrap="nowrap" align="right">Vorname:</td>
                            <td><input type="text" name="vorname" value="" size="32" /></td>
                    </tr>
                    <tr valign="baseline">
                            <td nowrap="nowrap" align="right">Bild:</td>
                            <td>
                            <input type="file" name="bild" id="fileField" /></td>
                            <?php // Configuration - Your Options
          
    $allowed_filetypes = array('.jpg','.gif','.bmp','.png','.pdf'); // These will be the types of file that will pass the validation.
          
    $max_filesize 5242880// Maximum filesize in BYTES (currently 5.0 MB).
          
    $upload_path ''// The place the files will be uploaded to (currently a 'files' directory).
       
    $filename $_FILES['bild']['name']; // Get the name of the file (including file extension).
       
    $ext substr($filenamestrpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
     
       // Upload the file to your specified path.
       
    if(move_uploaded_file($_FILES['bild']['tmp_name'],$upload_path $filename))?>
                    </tr>
                    <tr valign="baseline">
                            <td nowrap="nowrap" align="right">Upload1:</td>
                            <td><label>
                                            <input type="file" name="upload1" id="fileField2" />
                                            <?php // Configuration - Your Options
          
    $allowed_filetypes = array('.jpg','.gif','.bmp','.png','.pdf'); // These will be the types of file that will pass the validation.
          
    $max_filesize 5242880// Maximum filesize in BYTES (currently 5.0 MB).
          
    $upload_path ''// The place the files will be uploaded to (currently a 'files' directory).
       
    $filename $_FILES['upload1']['name']; // Get the name of the file (including file extension).
       
    $ext substr($filenamestrpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
     
       // Upload the file to your specified path.
       
    if(move_uploaded_file($_FILES['upload1']['tmp_name'],$upload_path $filename))?>
                            </label></td>
                    </tr>
                    <tr valign="baseline">
                            <td nowrap="nowrap" align="right">Upload2:</td>
                            <td><input type="file" name="upload2" id="fileField3" /></td>
                            <?php // Configuration - Your Options
          
    $allowed_filetypes = array('.jpg','.gif','.bmp','.png','.pdf'); // These will be the types of file that will pass the validation.
          
    $max_filesize 5242880// Maximum filesize in BYTES (currently 5.0 MB).
          
    $upload_path ''// The place the files will be uploaded to (currently a 'files' directory).
       
    $filename $_FILES['upload2']['name']; // Get the name of the file (including file extension).
       
    $ext substr($filenamestrpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
     
       // Upload the file to your specified path.
       
    if(move_uploaded_file($_FILES['upload2']['tmp_name'],$upload_path $filename))?>
                    </tr>
                    <tr valign="baseline">
                            <td nowrap="nowrap" align="right">&nbsp;</td>
                            <td><input type="submit" value="Datensatz einf&uuml;gen" /></td>
                    </tr>
            </table>
            <input type="hidden" name="id" value="" />
            <input type="hidden" name="datum" value="<?PHP=time(); ?>" />
            <input type="hidden" name="ip" value="<?PHP=$_SERVER["REMOTE_ADDR"];?>" />
            <input type="hidden" name="MM_insert" value="form1" />
    </form>
    <p>&nbsp;</p>
    </body>
    </html>
    Die IP - Adresse <input type="hidden" name="ip" value="<?PHP=$_SERVER["REMOTE_ADDR"];?>" />
    sowie das Datum <input type="hidden" name="datum" value="<?PHP=time(); ?>" />
    werden immer noch nicht in die DB gespeichert.

    Um den Email versand muss ich mich auch noch kümmern.

  4. #4
    TP-Supporter chorn bringt sich richtig ein Avatar von chorn
    Registriert seit
    Apr 2008
    Ort
    Verden
    Beiträge
    370
    Zitat Zitat von chorn Beitrag anzeigen
    Lass dir $insertSQL doch mal per "echo" ausgeben und guck nach was da drin steht.
    Ggf. mal hier posten.

  5. #5
    TP-Veteran kami bringt sich richtig ein
    Registriert seit
    Apr 2004
    Ort
    NRW
    Beiträge
    1.022
    Hallo Schamane69,


    kann es auch nicht.
    PHP-Code:
            <input type="hidden" name="datum" value="<?PHP=time(); ?>" />
            <input type="hidden" name="ip" value="<?PHP=$_SERVER["REMOTE_ADDR"];?>" />
    schau Dir mal diese zwei zeilen an.

    Fehlermeldung: Parse error: parse error in .... irgendwie.php on line 120
    _____________________
    gruss
    reinhold

    _____________________
    meine Site:
    http://www.rkami.de



  6. #6
    TP-Newbie schamane69 macht alles soweit korrekt
    Registriert seit
    Mar 2010
    Beiträge
    3

    Email benachrichtigung

    So nun klappt es auch mit dem Datum und der IP adresse
    HTML-Code:
    [CODE]  <input type="hidden" name="datum" value="<?PHP  echo date("d.m.Y"); ?>  " />
            <input type="hidden" name="ip" value="<?php echo $_SERVER['REMOTE_ADDR'];?> " />[/CODE]
    Jetzt suche ich noch eine Möglichkeit für die Email Benachrichtigung bei einem neuen Eintrag. Ich möchte ein Email bekommen bekommen wenn ein neuer eintrag erstellt wurde.

  7. #7
    TP-Veteran kami bringt sich richtig ein
    Registriert seit
    Apr 2004
    Ort
    NRW
    Beiträge
    1.022
    Hallo Schamane69,

    phpBuddy hat ein Gästebuch-Workshop geschrieben, da ist auch eine e-Mail-Benachrichtigung drin.
    _____________________
    gruss
    reinhold

    _____________________
    meine Site:
    http://www.rkami.de



  8. #8
    TP-Supporter chorn bringt sich richtig ein Avatar von chorn
    Registriert seit
    Apr 2008
    Ort
    Verden
    Beiträge
    370
    Oder einfach Doku lesen:

    http://php.net/mail

+ Antworten

Ähnliche Themen

  1. Kontaktformular mit "Upload"
    Von newx im Forum Dreamweaver & andere Webeditoren
    Antworten: 13
    Letzter Beitrag: 10.06.2011, 11:46
  2. [Tutorial] Formulare verarbeiten mit PHP/MySQL (Teil 3 - Datei Upload)
    Von phpBuddy im Forum Workshops und Tutorials
    Antworten: 22
    Letzter Beitrag: 31.03.2010, 01:29
  3. [php & mysql] bild upload
    Von jayjay im Forum Traum-Dynamik
    Antworten: 1
    Letzter Beitrag: 23.05.2006, 15:33
  4. Antworten: 1
    Letzter Beitrag: 19.04.2004, 10:15
  5. Bilddateien-Upload mit PHP/MySQL
    Von Ullamo im Forum Traum-Dynamik
    Antworten: 3
    Letzter Beitrag: 15.03.2003, 17:49

Stichworte

Aktive Benutzer

Aktive Benutzer

Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)

     

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51