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 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类