【发布时间】: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应该在查询中的单引号之间