【问题标题】:setting date and time in timestamp datatype using php使用 php 在时间戳数据类型中设置日期和时间
【发布时间】:2015-11-09 06:22:50
【问题描述】:

我正在使用 jQuery post 函数将数据从 html 发送到 PHP,但是日期和时间没有插入我的列中,我很困惑我的错误在哪里。 我的列数据类型是timestamp

这是我的jQuery 代码

function conf_suspenduser(arg)
{

    var day = $('#day').val();
    var month = $('#month').val();
    var year = $('#year').val();
    if(day == "" || month=="")
    {

        console.log('pelase insert')

    }
    else
    {

        var user = {
        arg:arg,
        day:day,
        month:month,
        year:year
                };

    $.post('conf_suspenduser.php',user,function(data)
    {
        console.log(data);
    })


    }

}

这是我的 php 代码

<?php

require('lib/db.php');
$db = new database();
$conn = $db->connection();

    $user_id = $_REQUEST['arg'];
    $day = $_REQUEST['day'];
    $month = $_REQUEST['month'];
    $year = $_REQUEST['year'];
      $date =  date("Y-m-d H:i:s", mktime(0,0,0,$year,$month,$day));
          $sql = "update user SET userActive = 2, updated = $date where userId = $user_id";
    $queryresult = $conn->query($sql);
    if ($queryresult === TRUE)
    {   
        echo 'updated..';
    }
    else
    {
        echo 'not updated..';
    }

?>

我正在从 html 中的选择标签中获取日期、日期、年份,比如 Facebook 正在做 即

<select id="month"><option value="1">Jan</option></select>
<select id="day"><option value="1">Jan</option></select>
<select id="year"><option value="2015">2015</option></select>

【问题讨论】:

  • 值是否正确发布??
  • 控制台是否为您提供:更新?
  • updated.. 消息是否输出到控制台?检查网络服务器上的日志 - 它是否有发布请求的记录?响应代码是什么?错误日志中有相应的条目吗?
  • 是的,我在 php 中正确获取值我的列更新类型是时间戳,请解决这个问题 :(
  • 我也认为$date 应该在查询中的单引号之间

标签: php jquery datetime .post


【解决方案1】:

我想我看到了你的问题:

错误:

date('Y-m-d', mktime(0, 0, 0, $year, $month, $day));

正确:

date('Y-m-d', mktime(0, 0, 0, $month, $day, $year));

所有参数:

date('Y-m-d H:i:s', mktime($hour, $minute, $second, $month, $day, $year));

信息:

http://php.net/manual/en/function.mktime.php

【讨论】:

  • 检查我提供的链接:)
猜你喜欢
  • 2013-06-16
  • 2012-04-15
  • 1970-01-01
  • 2015-11-17
  • 2016-04-05
  • 1970-01-01
  • 1970-01-01
  • 2010-10-31
  • 1970-01-01
相关资源
最近更新 更多