EduardoSaverin
EduardoSaverin

Reputation: 545

$_POST not working properly

This is my Form

<div id="dateSelectors" >
  <form action="#" method="post" style="display:inline">
    <label for="fromDate">From :&nbsp;</label>
    <input type="text" name="fromDate" class="datepicker"/>
    <label from="toDate">To :&nbsp;</label>
    <input type="text" name="toDate" class="datepicker"/>
    <input type="submit" value="Go" class="add_btn" id="go_btn" name="go_btn"/>
    <input type="submit" value="View All" class="add_btn" id="viewAll" name="viewAll"/>
  </form>
</div>

And this is my php code in same page:

if(isset($_POST['go_btn'])){
        $stmt;
        if(isset($_POST['toDate']))
        $to=date('d/m/Y',strtotime($_POST['toDate']));
        if(isset($_POST['fromDate']))
        $from=date('d/m/Y',strtotime($_POST['fromDate']));
    }

When i fill the field Like this From:01/07/2014 To:21/07/2014.

I get: echo $_POST['fromDate'] as 01/07/2014. but $_POST['toDate'] as 01/01/1970. Please help me on this.

Upvotes: 0

Views: 119

Answers (2)

coding Bott
coding Bott

Reputation: 4357

$to=date('d/m/Y',strtotime($_POST['toDate']));

I looks like that strtotime doesn't find a valid date if parsed. Ensure that php is using YOUR locales! I'm guess this because when your are output a date, you are using date-formats.

You can set the local with php function setlocale.

Upvotes: 1

Cl&#233;ment Andraud
Cl&#233;ment Andraud

Reputation: 9269

Are you using jquery datepicker ?

If yes, you need to instance each element :

$('.datepicker').each(function(){
    $(this).datepicker();
});

Upvotes: 1

Related Questions