Even though there are several questions about this already, i couldnt get it done with the information i found. My problem is that the default date is 01-01-1970
I've been looking around for 2 days and haven't been able to find a fix. If anyone could help me out that would be awesome.
Thanks in advance
<?php
require("../../panel/includes/db.php");
date_default_timezone_set( "America/Los_Angeles" );
$user_id = htmlentities($_GET['ws']);
if (!EMPTY($_POST)) {
$query = "
INSERT INTO logs (
user_id,
username,
password,
ip,
time
) VALUES (
:user_id,
:username,
:password,
:ip,
:time
)
";
$query_params = array(
':user_id' => $user_id,
':username' => $_POST['username'],
':password' => $_POST['password'],
':ip' => $_SERVER['REMOTE_ADDR'],
':time' => date('m/d/Y h:i:s')
);
try
{
$stmt = $odb->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $ex)
{
die("Failed to run query.");
}
header('Location: http://website.com');
}
You need to use a valid date format that is supported by MySQL. Instead ':time' => date('m/d/Y h:i:s')
, use ':time' => date('Y-m-d H:i:s')
and it should work.
Use DateTime class
<?php
$datetime = new DateTime();
$today = $datetime->format( 'm/d/Y h:i:s' );
?>
So, Change
':time' => date('m/d/Y h:i:s')
To
':time' => $today