duande1986 2015-11-23 14:49
浏览 41
已采纳

PHP Datepicker数据不会进入mySQL

I am building a application for web using php and mysql database. I am using a template for the frontend, bootstrap template, however, when I choose the date and submit the form, the date doesn't go into the mysql, I have set the data type for my date as DATE in mysql. i can't seem to figure out why. Here is the code for the date.

<div class="form-group">
    <label class="col-sm-3 control-label">Request Date</label>
      <div class="col-sm-6">
       <input class="input-sm input-s datepicker-input form-control" size="16" type="text" data-date-format="dd-mm-yyyy" name="requestDate" id="requestDate" data-required="true">
      </div>
 </div>

Here is the Execution code for the form:

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

print_r($_POST);
$id = $_POST['id'];
$seoSro = $_POST['seoSro'];
$projectStatus = $_POST['projectStatus'];
$requestDate = $_POST['requestDate ];
------ the correct one ---------
$requestDate = date("Y-m-d",strtotime($_POST['requestDate']));

Please help me guys, it enters 0000-00-00 data into the database.

  • 写回答

1条回答 默认 最新

  • dongqiao9394 2015-11-23 14:52
    关注

    mysql date format is yyyy-mm-dd,

    so before inserting the code, use strtotime() and convert the date to mysql format.

    $requestDate = date("Y-m-d",strtotime($_POST['requestDate']));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化