gpt4 book ai didi

PHP 添加日期 - mysqli_stmt::bind_param()

转载 作者:行者123 更新时间:2023-11-30 22:47:20 24 4
gpt4 key购买 nike

我正在尝试将日期字段添加到源并保存到 PHP/MySQL 数据库。我正在使用 phpMyAdmin 并将“edate”字段设置为“DATE”类型。

我保存数据的 PHP 文件是:

$statement = $db->stmt_init();

date_default_timezone_set('UTC');

$edate = $_POST['edate'];
$timestamp = date('dd-mm-yyyy', strtotime($edate));

//database insert statement
$statement->prepare("INSERT INTO events (lat, lon, name, description, category, edate) VALUES (?, ?, ?, ?, ?, '$timestamp')");

//grab values from the url and add to database
$statement->bind_param("ddsssi", $_POST['lat'], $_POST['lon'], $_POST['name'], $_POST['description'], $_POST['category'], $_POST['edate']);
$status = $statement->execute();

但是当我在浏览器中运行 PHP 文件时。它给出了以下错误:

Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement in /Users/Stephen/Sites/tidy_map/adddata.php on line 18

第 18 行是:

$statement->bind_param("ddsssi", $_POST['lat'], $_POST['lon'], $_POST['name'], $_POST['description'], $_POST['category'], $_POST['edate']);

该表单是使用 Google Maps API V3 的 Google map 的一部分 - 当一个新标记被添加到 map 时,它会打开一个信息窗口,其中显示带有一些 Javascript 的表单:

// Add Foem to New Info Window
google.maps.event.addListener(drawingManager, 'overlaycomplete', function (point)
{
//"clone" the event-form to put in the infowindow
var form = $(".event-form").clone().show();
var infowindow_content = form[0];
var infowindow = new google.maps.InfoWindow({
content: infowindow_content,
});

最佳答案

你应该试试这个,将你的时间戳绑定(bind)为一个字符串并告诉 postgres 将它转换为时间戳

//database insert statement
$statement->prepare("INSERT INTO events (lat, lon, name, description, category, edate) VALUES (?, ?, ?, ?, ?, STR_TO_DATE(?,'%d-%m-%Y'))");

//grab values from the url and add to database
$statement->bind_param("ddssss", $_POST['lat'], $_POST['lon'], $_POST['name'], $_POST['description'], $_POST['category'], $_POST['edate']);

关于PHP 添加日期 - mysqli_stmt::bind_param(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29237107/

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