0

I have tried so many possible solutions and it's just not working for me. I have the following code:

<div class="bootstrap-iso">
    <div class="container-fluid">
        <div class="row">
           <div class="col-md-6 col-sm-6 col-xs-12">
               <!-- datepicker code begins -->
               <div class="form-group"> <!-- Date input -->
                   <label class="control-label" for="date">Closing Date</label>
                   <input class="form-control" id="date" name="date" placeholder="YYYY-  MM-DD" type="date"/>
               </div>
           </div>
       </div>    
    </div>

Then I have the follownig:

<script>
    $(document).ready(function(){
        var date_input=$('input[name="date"]'); //our date input has the name "date"
        var container=$('.bootstrap-iso form').length>0 ? $('.bootstrap-iso form').parent() : "body";
        var options={
            format: 'yyyy-mm-dd',
            container: container,
            todayHighlight: true,
            autoclose: true,
        };
        date_input.datepicker(options);
    })
</script>

In my class I have the following code:

$newVacancy_stmt = $db->prepare('INSERT INTO vacancies (roleID, shortTitle, longTitle, roleDescription, roleResponsibilities, roleRequirements, createdBy, creationDate, publishDate, closeDate) VALUES (:roleID, :shortTitle, :longTitle, :roleDescription, :roleResponsibilities, :roleRequirements, :createdBy, NOW(), NOW(), ' . $closingDate . '))');

I convert my posted date with this:

$closingDate = date('Y-m-d', strtotime($_POST['date']));

Then I call my function:

$addVacancy = addNewVacancyInternal($roleID, $shortTitle, $longTitle, $roleDescription, $roleResponsibilities, $roleRequirements, $createdBy, $closingDate);

It does not insert the record into the DB. As soon as I take the date out (not inserting the date) it insert the record. Any suggestions please?

1
  • Check what value you are getting in $_POST['date']. Tell us the value. Commented Jun 16, 2017 at 6:11

1 Answer 1

1
$db->prepare('INSERT INTO vacancies (roleID, ...., publishDate, closeDate) 
                             VALUES (:roleID, .... NOW(), :closingDate))');

and pass $closingDate with the rest of the named parameters.

Sign up to request clarification or add additional context in comments.

8 Comments

$closingDate = date('Y-m-d', strtotime($_POST['date']));
$addVacancy = addNewVacancyInternal($roleID, $shortTitle, $longTitle, $roleDescription, $roleResponsibilities, $roleRequirements, $createdBy, $closingDate); $newVacancy_stmt = $db->prepare('INSERT INTO vacancies (roleID, shortTitle, longTitle, roleDescription, roleResponsibilities, roleRequirements, createdBy, creationDate, publishDate, closeDate) VALUES (:roleID, :shortTitle, :longTitle, :roleDescription, :roleResponsibilities, :roleRequirements, :createdBy, NOW(), NOW(), :closingDate))');
$newVacancy_stmt->bindParam(':closingDate', $closingDate, PDO::PARAM_STR); $addNewVacancy = $newVacancy_stmt->execute(); Is still not working thanks.
No, as soon as I insert the record without the date it insert.
are there any errors when you insert it with date? Also enable query log and check how the query looks when it reaches the db.
|

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.