Click here to Skip to main content
14,974,886 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm updating a legacy Web application to include a php form that once submitted inserts a date time stamp into a table in a MySQL database. The date format in the database is shown as: 2015-05-18 14:34:23.
However, when I display the date in the Web application it comes back as:
1969-12-31 19:33:35. Obviously, the default date of (Dec. 31, 1969) indicates a formatting error... which I'm not sure how to correct.

The sql code is as follows:
PHP
$title = mysql_real_escape_string($_POST['tofiles_title']);
$body = mysql_real_escape_string($_POST['tofiles_body']);
$link = "http://example.com/uploads/" . mysql_real_escape_string($_POST['tofiles_link']);
$relation = mysql_real_escape_string($_POST['tofiles_relation']);
$type = mysql_real_escape_string($_POST['tofiles_type']);
$date = date('Y-m-d H:i:s', time());
//$date = mysql_real_escape_string($_POST['tofiles_post_date']);
$ip = $_SERVER['REMOTE_ADDR'];
$post_user = $_SESSION['user_id'];

$sql = "INSERT INTO site_tofiles (tofiles_title, tofiles_body, tofiles_link, tofiles_relation, tofiles_type,  tofiles_post_date, tofiles_post_ip, tofiles_post_user) VALUES ";
$sql .= "('$title', '$body', '$link', '$relation', '$type', '$date', '$ip', '$user_id');";
mysql_query($sql);



NOTE: Elsewhere in the legacy Web application post dates are shown in the following format: May 13, 2015, 4:30 pm, and the date in the MySQL database is shown as: 1422475338. I think this is the UNIX code for date if I'm not mistaken.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900