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

查看:61
本文介绍了在php中提交编辑表单后,日期返回空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Date returns null values after submiting edit form in php

HTML CODE IS

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

虽然iam保存了数据..在更改日期后日期变为空值..add表单可以正常工作..但是编辑表单的日期却变为空值..请给我建议正确的代码..

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..

推荐答案

您好,如果填写的日期为空,请发送表的架构或提及日期字段的数据类型.由于您要保存不正确的数据类型,因此日期字段变为空. 数据类型date接受yy-mm--dd格式的日期,并且由于%m/%d/%Y格式为null,因此您给出了%m/%d/%Y格式.希望它会帮助你.

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. Hope it will hepl you.

这篇关于在php中提交编辑表单后,日期返回空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆