在数据库中写$ _SESSION

时间:2015-07-12 09:52:21

标签: php mysql session insert-into

我试图弄清楚为什么INSERT INTO不起作用。它适用于$ _POST但它不适用于$ _SESSION。这是我的代码:

第1步 - 这是我在结账过程中第一步使用的表格:

if (!empty($_POST)) {

    $sex = $_POST['sex'];
    $first_name = $_POST['first_name'];
    $family_name = $_POST['family_name'];
    $birthday = $_POST['birthday'];
    $address = $_POST['address'];
    $plz = $_POST['plz'];
    $city = $_POST['city'];
    $land = $_POST['land'];
    $email = $_POST['email'];
    $password = $_POST['password'];
    $password_confirmation = $_POST['password_confirmation'];
    $agbs = $_POST['agbs'];
    $newsletter = $_POST['newsletter'];
    $shipping_address = $_POST['shipping_address'];
    $shipping_plz = $_POST['shipping_plz'];
    $shipping_city = $_POST['shipping_city'];
    $shipping_land = $_POST['shipping_land'];
    $is_admin = $_POST['is_admin'];
    $created_at = time();

    // Validieren
    if (!empty($email) && !empty($family_name) && !empty($password) && !empty($password_confirmation) && !empty($agbs)) {

        if ($password == $password_confirmation) {

            $password_hash = password_hash($password, PASSWORD_BCRYPT);                                 );

            $_SESSION['sex'] = $sex;
            $_SESSION['first_name'] = $first_name;
            $_SESSION['family_name'] = $family_name;
            $_SESSION['birthday'] = $birthday;
            $_SESSION['address'] = $address;
            $_SESSION['plz'] = $plz;
            $_SESSION['city'] = $city;
            $_SESSION['land'] = $land;
            $_SESSION['email'] = $email;
            $_SESSION['password'] = $password;
            $_SESSION['password_hash'] = $password_hash;
            $_SESSION['agbs'] = $agbs;
            $_SESSION['newsletter'] = $newsletter;
            $_SESSION['shipping_address'] = $shipping_address;
            $_SESSION['shipping_plz'] = $shipping_plz;
            $_SESSION['shipping_city'] = $shipping_city;
            $_SESSION['shipping_land'] = $shipping_land;
            $_SESSION['is_admin'] = $is_admin;

            header("location: ?site=zahlungsart_waehlen");

            if($error = 1 && $mysql_error = mysqli_errno($link)) {


                if ($mysql_error == 1062) {
                    $email_error = "Deine Email Adresse existiert bereits";
                } else {
                    echo $mysql_error;
                }
            }
        // wenns nicht funktioniert: Fehler + Formular ausgeben
        } else {
            $error = 1;
            $pswrd_error = "Deine eingegebenen Passwörter stimmen nicht überein";

        }

    // wenns nicht funktioniert: Fehler + Formular ausgeben
    } else {
        $error = 1;
        // felder sind leer
        $fields_error = "Bitte fülle alle Felder aus";
    }
}

if ($error == 1 || empty($_POST)) {
    // Formular anzeigen
    $includes_from_logic[] = "views/checkout.php";
}

第2步 - 在第一步之后,我可以选择也写入会话的付款选项:

if (!empty($_POST)) {

      $sex = $_SESSION['sex'];
      $first_name = $_SESSION['first_name'];
      $family_name = $_SESSION['family_name'];
      $birthday = $_SESSION['birthday'];
      $address = $_SESSION['address'];
      $plz = $_SESSION['plz'];
      $city = $_SESSION['city'];
      $land = $_SESSION['land'];
      $email = $_SESSION['email'];
      $password = $_SESSION['password'];
      $password_hash = $_SESSION['password_hash'];
      $agbs = $_SESSION['agbs'];
      $newsletter = $_SESSION['newsletter'];
      $shipping_address = $_SESSION['shipping_address'];
      $shipping_plz = $_SESSION['shipping_plz'];
      $shipping_city = $_SESSION['shipping_city'];
      $shipping_land = $_SESSION['shipping_land'];
      $is_admin = $_SESSION['is_admin'];

      $sql = "INSERT INTO users (sex, first_name, family_name, address, plz, city, land, email, password_hash, agbs, newsletter, created_at, shipping_address, shipping_plz, shipping_city, shipping_land, birthday, is_admin) VALUES 
      ('$sex', '$first_name', '$family_name', '$address', '$plz', '$city', '$land', '$email', '$password_hash', '$agbs', '$newsletter', '$created_at', '$shipping_address', '$shipping_plz', '$shipping_city', '$shipping_land', '$birthday', 0)";

      $res = mysqli_query($link, $sql) or die($sql);
}

的var_dump($ _ SESSION);

array(23) { ["prozess"]=> array(6) { ["name"]=> string(3) "ddd" ["party"]=> string(10) "Regenbogen" ["birthdate"]=> string(10) "0002-02-22" ["guests"]=> string(1) "2" ["step"]=> string(6) "extras" ["partyPrice"]=> float(39.9) } ["cart"]=> array(0) { } ["is_recipient"]=> bool(true) ["sex"]=> NULL ["first_name"]=> string(7) "Beverly" ["family_name"]=> string(13) "Beverly Hills" ["birthday"]=> string(5) "Lrzfs" ["address"]=> string(15) "4782 Beverly Dr" ["plz"]=> string(4) "4782" ["city"]=> string(13) "Beverly Hills" ["land"]=> string(11) "Österreich" ["email"]=> string(26) "bhills_4782@mailinator.com" ["password"]=> string(1) "1" ["password_hash"]=> string(60) "$2y$10$M4FFQLuYJbyeIkGy7ZaOfuD0r4YVr3sL/O/JyLFe881h0BzCE8yse" ["agbs"]=> string(2) "JA" ["newsletter"]=> NULL ["shipping_address"]=> string(15) "4782 Beverly Dr" ["shipping_plz"]=> string(4) "4782" ["shipping_city"]=> string(13) "Beverly Hills" ["shipping_land"]=> string(11) "Österreich" ["is_admin"]=> NULL ["payment_method"]=> string(11) "Kreditkarte" ["bestellung_ueberpruefen"]=> NULL }

0 个答案:

没有答案