duane9322 2015-03-24 15:48
浏览 330

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

I'm trying to add a date field to a from and save to PHP/MySQL database. I'm using phpMyAdmin and have set the 'edate' field to 'DATE' type.

My PHP file to save the data is:

$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();

But when i run the PHP file in the browser. it gives teh following error:

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

with line 18 being:

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

The Form is part of a Google Map using Google Maps API V3 - when a new marker is added to the map, it opens an InfoWindow which displays the form with some 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,
    });
  • 写回答

2条回答 默认 最新

  • dongpeng8994 2015-03-24 16:24
    关注

    You should try this, bind your timestamp as a string and tell postgres to cast it to a timestamp

    //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']);
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度