此代码正在创建此错误 "错误:时间值不正确:' 2017-05-30 17:43:14 pm'对于专栏' time'在第1行和第34行; 请有人帮我解决这个错误
<?php
include 'database.php';
//check if form is submitted
if(isset($_POST['submit'])){
$user = mysqli_real_escape_string($con, $_POST['user']);
$message = mysqli_real_escape_string($con, $_POST['message']);
//set date
date_default_timezone_set('Asia/Kolkata');
$time = date('Y-m-d H:i:s a', time());
//validation
if(!isset($user) || $user=='' || !isset($message) || $message == ''){
$error = "Please fill in your Name and Message";
header("Location: index.php?error=" .urlencode($error));
exit();
}else{
$query = "INSERT INTO shouts (user, message, time) VALUES('$user', '$message', '$time')";
if(!mysqli_query($con, $query)){
die('Error: ' .mysqli_error($con));
}else{
header("Location: index.php");
exit();
}
}
}
答案 0 :(得分:1)
Mysql&#39; DATE&#39;列类型接受以下日期格式&#39; Y-m-d&#39; &#39; DATETIME&#39;栏接受&#39; Y-m-d H:i:s&#39; 此外&#39; 2017-05-30 17:43:14 pm&#39; PM部分没有做任何事情,因为17:43:14有所需的所有信息。 检查列类型并相应地调整输入格式。