gpt4 book ai didi

PHP PDO 准备插入查询。值未传递的问题

转载 作者:行者123 更新时间:2023-11-29 06:23:36 25 4
gpt4 key购买 nike

我正在使用 PDO 在 php 和 MySQL 中执行准备好的查询。查询执行时没有错误,但有一个参数未正确传递其值。它作为空白字段出现,但不是 NULL。这真的很奇怪,因为我输入的代码似乎与其他人一样,当然工作得很好。真是令人沮丧。

$f_name = $_POST['f_name'];
$l_name = $_POST['l_name'];
$email = $_POST['email'];
$pass = $_POST['pass'];
$address1 = $_POST['address_1'];
$address2 = $_POST['address_2'];
$suburb = $_POST['suburb'];
$city = $_POST['city'];
$country = $_POST['country'];
$phone = $_POST['phone'];



include('db_connect.php');

$stmt = $db_connection->prepare('INSERT INTO tblUser (userID,fName, lName, email, password, addressLine1, suburb, city, country, phone) VALUES( NULL, :f_name, :l_name, :email, :pass, :address1, :suburb, :city, :country, :phone)');
$stmt->bindParam(':f_name', $f_name, PDO::PARAM_STR);
$stmt->bindParam(':l_name', $l_name, PDO::PARAM_STR);
$stmt->bindParam(':email', $email, PDO::PARAM_STR);
$stmt->bindParam(':pass', $pass, PDO::PARAM_STR);
$stmt->bindParam(':address1', $address1, PDO::PARAM_STR);
//$stmt->bindParam(':address2', $address2, PDO::PARAM_STR);
$stmt->bindParam(':suburb', $suburb, PDO::PARAM_STR);
$stmt->bindParam(':city', $city, PDO::PARAM_STR);
$stmt->bindParam(':country', $country, PDO::PARAM_STR);
$stmt->bindParam(':phone', $phone, PDO::PARAM_STR);

try {
$stmt->execute();
print_r($stmt);
$result = $stmt->fetchAll();
}
catch (Exception $e) {
echo $e;
}

print_r($_POST) 的输出;是: 数组 ( [email] => test@test.com [pass] => pass [pass_confirm] => pass [f_name] => fefs [l_name] => sfasafs [address_1] => sfafsa [address_2] => dsfsafsaf [郊区] => dffdsa [城市] => dsffdf [国家/地区] => sfaafdsa [电话] => fsaafssaf [提交] => 注册)

问题是数据库已填充新记录,但密码字段为空。我删除了哈希以简化事情。

这是用户表的SQL:

CREATE TABLE IF NOT EXISTS `tbluser` (
`userID` int(11) NOT NULL AUTO_INCREMENT,
`password` varchar(40) NOT NULL,
`email` varchar(60) NOT NULL,
`addressLine1` varchar(30) DEFAULT NULL,
`addressLine2` varchar(30) DEFAULT NULL,
`suburb` varchar(30) DEFAULT NULL,
`city` varchar(30) DEFAULT NULL,
`country` varchar(40) DEFAULT NULL,
`phone` varchar(25) DEFAULT NULL,
`fName` varchar(30) DEFAULT NULL,
`lName` varchar(30) NOT NULL,
`admin` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`userID`),
UNIQUE KEY `email` (`email`),
UNIQUE KEY `email_3` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;

最佳答案

您不会碰巧在 db_connect.php 中定义 $pass 吧?如果这样做,它将覆盖您原来的声明。

关于PHP PDO 准备插入查询。值未传递的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1591983/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com