INSERT命令没有被执行?

时间:2014-05-11 14:42:34

标签: php mysql sql pdo

对于学校我需要复制一个荷兰ISP的订单页面(我是荷兰语),我已经制作了表格并且数据被正确地放在变量中。但是当我想使用PDO来执行INSERT语句时,我在指定的表中没有获得新行,并且没有明确的错误(我得到0000)。连接很好,因为我对其他SELECT语句使用相同的连接。我无法弄清楚出了什么问题。任何帮助表示赞赏。代码如下:

step3.php,代码检查前两步是否执行($ _COOKIE order and user_data)

    <?php

    include_once "pagelayout.php"; include_once "functions.php";

    boven("Stap 3 -- Bestellen Bij ..");

        if (isset($_COOKIE['order'])) {

            if (isset($_COOKIE['user_data'])) {

?>

    <img src="files/loading.GIF"> <br> <h3> Verwerken bestelling.... </h3>  <p> Een moment geduld </p>          
    <!-- <meta http-equiv="refresh" content="10;URL='done.php'" /> --> 

<?php

            save_user_data();

            }

            else  { header('Location: step2.php');  } 
        }

        else { header('Location: index.php'); }


    beneden();


?>

这些函数存储在functions.php中:

function save_user_data() {

    $order_data = unserialize($_COOKIE['order']);
    $user_data = unserialize($_COOKIE['user_data']);

    $sqladres_postcode = $user_data['adres_postcode'];
    $sqladres_huisnummer = $user_data['adres_huisnummer'];
    $sqladres_straat = $user_data['adres_straat'];
    $sqladres_plaats = $user_data['adres_plaats'];
    $sqlpersoon_sex = $user_data['persoon_sex'];
    $sqlpersoon_voorletters = $user_data['persoon_voorletters'];
    $sqlpersoon_tussenvoegsel = $user_data['persoon_tussenvoegsel'];
    $sqlpersoon_achternaam = $user_data['persoon_achternaam'];
    $sqlpersoon_geboortedatum = $user_data['persoon_geboortedatum'];
    $sqlpersoon_email = $user_data['persoon_email'];
    $sqlpersoon_telefoonnummer = $user_data['persoon_telefoonnummer'];
    $sqlbetaling_bankrekening = $user_data['betaling_bankrekening'];
    $sqlorder_allinone = $order_data['allinone'];
    $sqlorder_extra = serialize($order_data['extra']);
    $sqlorder_benefit = $order_data['benefit'];
    $sqlorder_totalmonthPrice = $_COOKIE['totalmonthPrice'];
    $sqlorder_totaloncePrice = $_COOKIE['totaloncePrice'];

    include_once "connection.php";

    $verbinding = connection_klant();   

    $sql = "INSERT INTO klant (adres_postcode, adres_huisnummer, adres_straat, adres_plaats, persoon_sex, persoon_voorletters, persoon_tussenvoegsel, persoon_achternaam, persoon_geboortedatum, persoon_email, persoon_telefoonnummer, betaling_bankrekening, order_allinone, order_extra, order_benefit, order_totalmonthPrice, order_totaloncePrice) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

    $statement = $verbinding->prepare($sql); 
    $statement -> bindValue (1, $sqladres_postcode, PDO::PARAM_STR);
    $statement -> bindValue (2, $sqladres_huisnummer, PDO::PARAM_STR);
    $statement -> bindValue (3, $sqladres_straat, PDO::PARAM_STR);
    $statement -> bindValue (4, $sqladres_plaats, PDO::PARAM_STR);
    $statement -> bindValue (5, $sqlpersoon_sex, PDO::PARAM_STR);
    $statement -> bindValue (6, $sqlpersoon_voorletters, PDO::PARAM_STR);
    $statement -> bindValue (7, $sqlpersoon_tussenvoegsel, PDO::PARAM_STR);
    $statement -> bindValue (8, $sqlpersoon_achternaam, PDO::PARAM_STR);
    $statement -> bindValue (9, $sqlpersoon_geboortedatum, PDO::PARAM_STR);
    $statement -> bindValue (10, $sqlpersoon_email, PDO::PARAM_STR);
    $statement -> bindValue (11, $sqlpersoon_telefoonnummer, PDO::PARAM_STR);
    $statement -> bindValue (12, $sqlbetaling_bankrekening, PDO::PARAM_STR);
    $statement -> bindValue (13, $sqlorder_allinone, PDO::PARAM_STR);
    $statement -> bindValue (14, $sqlorder_extra, PDO::PARAM_STR);
    $statement -> bindValue (15, $sqlorder_benefit, PDO::PARAM_STR);
    $statement -> bindValue (16, $sqlorder_totalmonthPrice, PDO::PARAM_STR);
    $statement -> bindValue (17, $sqlorder_totaloncePrice, PDO::PARAM_STR);

    echo $sql;

    $statement->execute();

    print_r($verbinding->errorInfo());


}

创建数据库的Sql文件:

/*
Navicat MySQL Data Transfer

Source Server         : localhost
Source Server Version : 50613
Source Host           : localhost:3307
Source Database       : klantendb

Target Server Type    : MYSQL
Target Server Version : 50613
File Encoding         : 65001

Date: 2014-05-11 16:37:55
*/

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for `klanten`
-- ----------------------------
DROP TABLE IF EXISTS `klanten`;
CREATE TABLE `klanten` (
  `adres_postcode` varchar(6) NOT NULL,
  `adres_huisnummer` varchar(100) NOT NULL,
  `adres_straat` varchar(100) NOT NULL,
  `adres_plaats` varchar(100) NOT NULL,
  `persoon_sex` varchar(100) NOT NULL,
  `persoon_voorletters` varchar(100) NOT NULL,
  `persoon_tussenvoegsel` varchar(100) DEFAULT NULL,
  `persoon_achternaam` varchar(100) NOT NULL,
  `persoon_geboortedatum` varchar(100) NOT NULL,
  `persoon_email` varchar(150) NOT NULL,
  `persoon_telefoonnummer` varchar(10) NOT NULL,
  `betaling_bankrekening` varchar(100) NOT NULL,
  `order_allinone` varchar(100) NOT NULL,
  `order_extra` varchar(100) DEFAULT NULL,
  `order_benefit` varchar(100) NOT NULL,
  `order_totalmonthPrice` varchar(100) NOT NULL,
  `order_totaloncePrice` varchar(100) DEFAULT NULL,
  `ID` int(10) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

-- ----------------------------
-- Records of klanten
-- ----------------------------
INSERT INTO `klanten` VALUES ('9999AA', '16', '', '', '', '', null, '', '', '', '', '', '', null, '', '', null, '3');

使用的连接:

function connection_klant() {

    $hostname_localhost  = "localhost";
    $port_localhost      = "3307";
    $database_localhost  = "klantendb";
    $username_localhost  = "root";
    $password_localhost  = "usbw";

    return new PDO("mysql:host=$hostname_localhost;dbname=$database_localhost;port=$port_localhost",$username_localhost,$password_localhost);

0 个答案:

没有答案