我在用户表中添加了一个新行,以显示每个用户的创建日期。我为此尝试了时间戳和日期时间类型,但它仍然在每个用户旁边显示 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());
这是显示信息的代码
$select_users = "SELECT * FROM users";
$result = mysql_query($select_users);
while ($user = mysql_fetch_array($result)) {
$user_row = sprintf(
"<td><input type='checkbox' name='checkbox[]' id='checkbox[]' value='%d'/></td>" .
"<td>%s %s</td> " .
"<td>%s</td>" .
"<td><a href='mailto:%s'>%s</a></td> " .
"<td>%s</td>" .
"<td><a href='javascript:delete_user(%d);'><img class='delete_user' src='images/trash.png' alt='' title='' border='0' /></a></td>",
$user['user_id'], $user['first_name'], $user['last_name'], $user[username],
$user['email'], $user['email'], $user['created'], $user['user_id']);
echo $user_row;
除了显示 0000-00-00 00:00:00 的创建日期外,我得到了正确显示的所有字段。我不知道我做错了什么。感谢您的帮助。
编辑:我已经有一个名为“updated”的字段,它使用“Current_timestamp”。