我有一个问题,有3个文本框输入日期,标题和内容。当我处理它在mysql数据库发送。文本框的日期不能发送到mysql数据库。只发送标题和内容。
我需要你的帮助来解决这个错误。谢谢你的帮助if(isset($_POST['submit'])){
$postdate=date($_POST['postdate']);
$title= htmlspecialchars($_POST['title']);
$content=$_POST['content'];
$sql=mysql_query("insert into national_news(postdate,title,content)values('$postdate','$title','$content')");
header("Location: nasional_news.php");
}
如果日期是从用户那里获得的,那么为什么要使用date()
函数?试试这个:
if(isset($_POST['submit'])){
$postdate=mysql_real_escape_string(trim($_POST['postdate']));
$title= mysql_real_escape_string(trim($_POST['title']));
$content= mysql_real_escape_string(trim($_POST['content']));
$sql=mysql_query("insert into national_news(postdate,title,content)values('$postdate','$title','$content')");
header("Location: nasional_news.php");
}
您的用户如何进入postdate
?你的线路,$postdate=date($_POST['postdate']);
将是无用的,除非用户实际输入"fm Y"之类的东西。查找php.net的日期页
您应该只接受postdate
,而不通过date()
函数运行它。
<?php
if(isset($_POST['submit']))
{
print_r($_POST);//Checking $_POST array values.
首先,您必须检查所有值从上一页张贴,然后继续您的代码。如果选中,则确保您的'postdate'列数据类型为'date',并每次使用query()或die()来了解查询执行状态。
对于印度的当前日期时间使用
$dateTime = new DateTime("now", new DateTimeZone('Asia/Calcutta'));
$dt= $dateTime->format("Y-m-d H:i:s");//for India