Ankündigung

Einklappen
Keine Ankündigung bisher.

PHP SQL prepared statements

Einklappen

Neue Werbung 2019

Einklappen
Dieses Thema ist geschlossen.
X
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • PHP SQL prepared statements

    Hallo,
    Ich würde gerne Daten aus einem Kontaktformular in eine Tabelle übermitteln. Hier der Code, den ich so weit verfasst habe:

    PHP-Code:
    $servername "";
    $username "";
    $password "";
    $dbname "";

    // Create connection
    $conn mysqli_connect($servername$username$password$dbname);

    // Check connection
    if (!$conn) {

        die(
    "Connection failed: " mysqli_connect_error());
    }

    $sqlid "SELECT id FROM contact ORDER BY id DESC LIMIT 1";
    $result mysqli_query($conn$sqlid);
    $row=mysqli_fetch_assoc($result);
    $last_id $row["id"];

    if (
    $last_id == "") {
    $fromid "0"; global $fromid;
    } else {
    $fromid $last_id+1; global $fromid;
    }

    global 
    $fromid;
    global 
    $fromname$frommail$name_company$mail_company$phone_company$adress_company$city_company$country_company$text;

    $stmt mysqli_stmt_init($conn);
    $sql mysqli_stmt_prepare($stmt'INSERT INTO contact (id, name, mail, company, mail_company, phone_company, adress_company, city, country, message)
    VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
    );
    mysqli_stmt_bind_param($sql'isssssssss'$fromid$fromname$frommail$name_company$mail_company$phone_company$adress_company$city_company$country_company$text);
    mysqli_stmt_execute($stmt);
    mysqli_stmt_error($stmt); //debugging

    print_r($_POST); //debugging

    /* $sql = "INSERT INTO contact (id, name, mail, company, mail_company, phone_company, adress_company, city, country, message)
    VALUES ('$fromid', '$fromname', '$frommail', '$name_company', '$mail_company', '$phone_company', '$adress_company', '$city_company', '$country_company', '$text')"; */

    if (mysqli_query($conn$sql)) {
        echo 
    "New record created successfully";

    } else {
        echo 
    "Error: " $sql "<br>" mysqli_error($conn);
    }
    mysqli_stmt_close($stmt);
    mysqli_close($conn); 
    Ich erhalte folgende Fehlermeldung:

    Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in C:\xampp\htdocs\websitetemplates\white_blue_scroll bar_1200px_width\content\connect.php on line 38
    Folgendermaßen sieht die Struktur der Tabelle 'user' aus:



    Danke im Voraus.

    edit:
    Achja, $fromname, $frommail, $name_company, $mail_company, $phone_company, $adress_company, $city_company, $country_company und $text wurden außerhalb der Funktion definiert, die hier im Code Snippet zu sehen ist, deswegen sind diese global. All diese Variablen sind folgendermaßen definiert worden:

    PHP-Code:
    $fromname $_POST["fromname"]; 

  • #2
    http://www.php-resource.de/forum/php...tatements.html

    http://phpforum.de/forum/showthread.php?t=284439

    Kommentar


    • #3
      [MOD: geschlossen, CrossPost]
      Competence-Center -> Enjoy the Informatrix
      PHProcks!Einsteiger freundliche TutorialsPreComposed Packages

      Kommentar

      Lädt...
      X