0

Hi Php'ers,
I'm new to Php.

I have some issues INSERTING date to MySQL by PHP.
here's my code snippet:

//date format
$date1 = mysqli_real_escape_string($_POST['j_avail']);
$d1 = date('Y-m-d',($date1));

$date2 = mysqli_real_escape_string($_POST['j_expir']);
$d2 = date('Y-m-d',($date2));

the query:

$sql = "INSERT INTO table (....,j_avail,j_expir) 
VALUES (....,'$d1','$d2')";

the HTML:

<td id="ititle">Availability :</td>
<td><input type="date" name="avail" id="datep"></td>
</tr>
<tr>
<td id="ititle">Expiration :</td>
<td><input type="date" name="exp" id="datep"></td>
</tr>

When i execute my the code and check my db i get this 1970-01-01.
i also have tried strtotime it also gives me this result.

Dont know whats the issue here. hmmmm

Thanks.

OTEP

Edited by pritaeas: Fixed markdown.

3
Contributors
2
Replies
14
Views
2 Years
Discussion Span
Last Post by Hilal2009
0

if you look at the manual:

http://php.net/manual/en/function.date.php 

You see that the second parameter is a timestamp. You are passing a string (from the POST array), so I am wondering what you entered into it.

Do:

print_r($_POST['date1']);
print_r($_POST['date2']);

and show the output.

Edited by pritaeas

0

I know it, change to this one

$d1 = date('Y-m-d',(strtotime($date1)));

$d2 = date('Y-m-d',(strtotime($date2)));

I hope it will work fine, is it?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.