gpt4 book ai didi

PHP PDO 准备插入 - 不插入数据且不显示错误

转载 作者:可可西里 更新时间:2023-11-01 07:13:47 26 4
gpt4 key购买 nike

<分区>

这个问题快把我逼疯了,我什么都试过了。没有给我任何错误,但它也没有向数据库插入任何内容。数据库连接良好,应该没有错别字。请看一下,看看您是否能找到问题所在:

$err = array();

if (isset($_POST['submit'])) {

$ip = gethostbyname($_SERVER['REMOTE_ADDR']);
$date = "2012-02-02 02:02:02"; //Example
$uploader_name = $_POST['uploader_name'];

// Validation happens here...


if (empty($err)) {

$host = "host";
$dbname = "db";
$user = "user";
$pass = "pass";

try {
$dbh = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);

$sql = "INSERT INTO `table` (`ip`, `date`, `uploader_name`)
VALUES (:ip, :date, :uploader_name)";
$stmt = $dbh->prepare($sql);

# the data we want to insert
$params = array(
':ip' => $ip,
':date' => $date,
':uploader_name' => $uploader_name
);


$stmt->execute($params);

$dbh = null;

} catch(PDOException $pe) {
die('SQL Error');
}


if (empty($err)) {
$err[] = "Success!";
}
}

}

此外,我确定它到达了插入部分,因为我收到了“成功”消息。

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