我之前问过一个类似的问题,但仍然没有得到有效的答案。所以我在我的数据库中有一个表,其中包含有关用户的信息(名字,电子邮件...)和 2 个字段,其中包含创建日期(“创建”)和更新日期(“更新”)。“更新”字段的类型为 TIMESTAMP ,默认为 ="CURRENT_TIMESTAMP",属性 ="on Current_timestamp" 。并且“created”字段具有 type="datetime" 而不是 null default="none"。问题是在显示创建日期时,我在每个用户“0000-00-00 00:00:00”旁边。这是将用户添加到数据库的代码:
$first_name = trim($_REQUEST['first_name']);
$last_name = trim($_REQUEST['last_name']);
$username = trim($_REQUEST['username']);
$password = trim($_REQUEST['password']);
$email = trim($_REQUEST['email']);
$created = strftime("%Y-%m-%d %H:%M:%S", time());
$insert_sql = sprintf("INSERT INTO users (first_name, last_name, username, password, email, created)" .
"VALUES('%s', '%s', '%s', '%s', '%s', '%s');",
mysql_real_escape_string($first_name),
mysql_real_escape_string($last_name),
mysql_real_escape_string($username),
mysql_real_escape_string(crypt($password, $username)),
mysql_real_escape_string($email),
mysql_real_escape_string($created));
mysql_query($insert_sql) or die(mysql_error());
请帮忙,我尝试了各种函数,如 date()、now(),但仍然不起作用。
编辑:我的表格显示的内容:
mysql> SELECT updated, created from users;
+---------------------+---------------------+
| updated | created |
+---------------------+---------------------+
| 2012-09-21 09:09:49 | 0000-00-00 00:00:00 |
| 2012-09-21 09:27:27 | 0000-00-00 00:00:00 |
| 2012-09-22 11:36:19 | 0000-00-00 00:00:00 |
| 2012-09-22 11:43:35 | 0000-00-00 00:00:00 |
+---------------------+---------------------+