Date在php中提交编辑表单后返回00 0000个值

Date在php中提交编辑表单后返回00 0000个值,php,mysql,Php,Mysql,在php中提交编辑表单后,Date返回空值 HTML代码是 <form class="form-horizontal" action="" method="post" > <label for="coupon_strt_date" >Start Date</label> <input type="text" name="coupon_strt_date" id="datepicker" value="<?php echo

在php中提交编辑表单后,Date返回空值

HTML代码是

<form  class="form-horizontal"  action="" method="post" >
    <label for="coupon_strt_date" >Start Date</label>


     <input type="text" name="coupon_strt_date" id="datepicker"  value="<?php echo $cats_rows['coupon_strt_date'];  ?>" class='datepick'>
    <label for="coupon_exp_date" class="control-label">Exp Date</label>
    <input type="text" name="coupon_exp_date"  value="<?php echo $cats_rows['coupon_exp_date'];  ?>" id="datepicker" class='datepick'>

    <input type="submit" name="submit" value="submit">
    </form>


    <?php
include("config.php");

$tbl_name = "coupons";
if (isset($_POST['submit'])){
$id=$_POST['id'];
    $coupon_strt_date = $_POST['coupon_strt_date'];
    $coupon_exp_date = $_POST['coupon_exp_date'];

$sql="update $tbl_name set coupon_strt_date = STR_TO_DATE('$_POST[coupon_strt_date]', '%m/%d/%Y'), coupon_exp_date = STR_TO_DATE('$_POST[coupon_exp_date]', '%m/%d/%Y') where id='$id'";
if (!mysql_query($sql))
  {
 echo "Error Accured";
  }
  else {
 echo " Successfull";
  }
}

开始日期
试试这个:

<?php
    $coupon_strt_date = date('Y-m-d', strtotime($_POST['coupon_strt_date']));
    $coupon_exp_date = date('Y-m-d', strtotime($_POST['coupon_exp_date']));

    $sql="update $tbl_name set coupon_strt_date = '$coupon_strt_date', coupon_exp_date = '$coupon_exp_date' where id='$id'";
?>
试试这个:

<?php
    $coupon_strt_date = date('Y-m-d', strtotime($_POST['coupon_strt_date']));
    $coupon_exp_date = date('Y-m-d', strtotime($_POST['coupon_exp_date']));

    $sql="update $tbl_name set coupon_strt_date = '$coupon_strt_date', coupon_exp_date = '$coupon_exp_date' where id='$id'";
?>

日期需要以
YYYY-MM-DD格式存储在数据库中。

日期需要以
YYYY-MM-DD格式存储在数据库中。

您在输入什么?你为什么不消毒?你的表格结构是什么?使用日期选择器格式是M D Y。你为什么多次发布同一个问题?你的问题下面有一个编辑链接你在输入什么?你为什么不消毒?你的表格结构是什么?使用日期选择器格式是M D Y。你为什么多次发布同一个问题?你的问题下面有一个编辑链接。嗨,谢谢。。这很好。嗨,谢谢。。这很好用。。