PHP通过表单输入日期并对其进行处理
我有一个问题,有3个文本框输入日期,标题和内容。当我处理它时,将其发送到mysql数据库中。Textbox postdate无法发送到mysql数据库。只发送标题和内容 我需要你的帮助来解决这个错误。谢谢你的帮助PHP通过表单输入日期并对其进行处理,php,mysql,forms,date,Php,Mysql,Forms,Date,我有一个问题,有3个文本框输入日期,标题和内容。当我处理它时,将其发送到mysql数据库中。Textbox postdate无法发送到mysql数据库。只发送标题和内容 我需要你的帮助来解决这个错误。谢谢你的帮助 if(isset($_POST['submit'])){ $postdate=date($_POST['postdate']); $title= htmlspecialchars($_POST['title']); $content=$_POST['conten
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($\u POST['postdate'])除非用户实际输入类似“F m Y”的内容,否则代码>将无效。仰望
您应该只接受postdate
,而不通过date()
函数运行它。可能是通过表单提交的postdate和postdate的表架构没有对齐。你能发布你的表模式吗?很好的SQL注入漏洞。享受你的站点/DB打印…只需在文本框中输入格式日期,不能输入字符串,给我指路?
<?php
if(isset($_POST['submit']))
{
print_r($_POST);//Checking $_POST array values.
$dateTime = new DateTime("now", new DateTimeZone('Asia/Calcutta'));
$dt= $dateTime->format("Y-m-d H:i:s");//for India