2

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.

4
  • data-date-format="dd-mm-yyyy" What is the format in your date column? Commented Nov 23, 2015 at 14:50
  • 1
    Please, post result of var_dump($_REQUEST['requestDate']); Commented Nov 23, 2015 at 14:51
  • there's no MySQL here, no db schema. Commented Nov 23, 2015 at 14:52
  • Where is your php code? Commented Nov 23, 2015 at 14:52

1 Answer 1

6

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']));
Sign up to request clarification or add additional context in comments.

7 Comments

OP has data-date-format="dd-mm-yyyy" so they could do data-date-format="yyyy-mm-dd" also. While making sure their column is date type. Otherwise, it won't work.
@Fred-ii- usually for end users, we should show in dd-mm-yyy format, so keping that in mind i gave this answer
@Fred-ii- dont consider as argument, i just said what even was there in my mind for this answer.
lol I don't think you understand what I meant by that. I meant that what you said in your comment is true. I think we're having a culture clash when it comes to expressions ;-)
hi @NiranjanNRaju, I tried the solution you gave, but the data still doesn't enters my sql
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.