简体   繁体   English

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

[英]Date returns null values after submiting edit form in php

Date returns null values after submiting edit form in php 在php中提交编辑表单后,日期返回空值

HTML CODE IS

<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";
  }
}

While iam saving data.. Dates are getting null value after chaning the date..add form is working fine..but edit form is dates are getting null value.. please sugguest me with correct code.. 虽然IAM保存数据..日期更改日期后日期变为空值..添加表单工作正常..但编辑表单日期变为空值..请给我建议正确的代码..

Hi if the date filled is getting null please send the schema of table or mention the data type of date field. 您好,如果填写的日期为空,请发送表格架构或提及日期字段的数据类型。 The date field is getting null because you are trying to save improper data types. 由于您要保存不正确的数据类型,因此日期字段变为空。 data type date accept date in yy-mm--dd format and you are giving %m/%d/%Y format due to which it is getting null. 数据类型date接受yy-mm--dd格式的日期,由于%m /%d /%Y格式为null,因此您给出的格式为%m /%d /%Y。 Hope it will hepl you. 希望它会帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM