无法更新日期时间字段,值变为0000:00:00 00:00:00

时间:2016-08-01 09:39:22

标签: php mysql

什么是我做错了,datetime字段没有得到更新,而是值变为全0

echo print_r($_POST);;
$time_in = $_POST['time_in'];
$time_out = $_POST['time_out'];

$id = $_GET['id'];

echo $sql = "UPDATE hours SET time_in = '".$time_in."' AND time_out = '".$time_out."' WHERE id = '".$id."'";
mysql_query($sql) or die(mysql_error());

1 个答案:

答案 0 :(得分:-1)

使用以下代码

echo print_r($_POST);;
$time_in = date('Y-m-d H:i:s',strtotime($_POST['time_in']));
$time_out = date('Y-m-d H:i:s',strtotime($_POST['time_out']));

$id = $_GET['id'];

echo $sql = "UPDATE hours SET time_in = '".$time_in."', time_out = '".$time_out."' WHERE id = '".$id."'";
mysql_query($sql) or die(mysql_error());