Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8569739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:24:23+00:00 2026-06-11T18:24:23+00:00

I previously asked a similar question, but still didn’t get a working answer. So

  • 0

I previously asked a similar question, but still didn’t get a working answer.
So I have in my database a table wich contains informations about users(first_name,email…) and 2 fields containing the date of creation(“created”) and the date of update(“updated”).
the “updated” field has the type TIMESTAMP ,default =”CURRENT_TIMESTAMP”, attributs =”on Current_timestamp” . And the “created” field has type=”datetime” and not null default=”none”.
The problem is when displaying the date of creation, I got next to each user “0000-00-00 00:00:00”.
Here is the code that adds a user to the database:

$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());

Please help, I tried various functions like date(), now() but still doesn’t work.

EDIT: that what my table shows:

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 |
+---------------------+---------------------+
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:24:24+00:00Added an answer on June 11, 2026 at 6:24 pm

    You are entering a string in a timestamp field; instead use the mysql function NOW(). Your query should be:

    "INSERT INTO `users` (
         `first_name`,
         `last_name`,
         `username`,
         `password`,
         `email`,
         `created`) VALUES (
                '%s',
                '%s',
                '%s',
                '%s',
                '%s',
                NOW())"
    

    Also, consider migrating to mysqli to take advantage of prepared statements.

    To clarify the comments; it won’t matter what type the field is, as MySQL will know how to deal with it if you give it NOW():

    mysql> create table temp (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, ts TIMESTAMP, dt DATETIME);
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> insert into temp values ('',NOW(),NOW()),('',NOW(),NOW());
    Query OK, 2 rows affected, 2 warnings (0.08 sec)
    Records: 2  Duplicates: 0  Warnings: 0
    
    mysql> select * from temp;
    +----+---------------------+---------------------+
    | id | ts                  | dt                  |
    +----+---------------------+---------------------+
    |  1 | 2012-09-22 13:38:50 | 2012-09-22 13:38:50 |
    |  2 | 2012-09-22 13:38:50 | 2012-09-22 13:38:50 |
    +----+---------------------+---------------------+
    2 rows in set (0.00 sec)
    

    It won’t work, if you try to insert UNIX_TIMESTAMP():

    mysql> insert into temp values ('',UNIX_TIMESTAMP(),UNIX_TIMESTAMP());
    Query OK, 1 row affected, 3 warnings (0.00 sec)
    
    mysql> select * from temp order by id desc limit 1;
    +----+---------------------+---------------------+
    | id | ts                  | dt                  |
    +----+---------------------+---------------------+
    |  7 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |
    +----+---------------------+---------------------+
    1 row in set (0.00 sec)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have asked a similar question previously but it was never resolved so here
I have asked a similar question previously, but posting a new one as I
I have a problem similar to this question which was previously asked but my
Ok, I have previously asked a similar question to this but it was voted
I have asked a similar question previously, but 1. no one answered and 2.
A similar question was previously asked, but none of the answers really provided what
I asked a similar question previously, but it was so vague that I couldn't
I have previously asked a question on AS3 and timing for games but got
I have asked a similar question before here , but after much thought, and
I asked a similar question about this previously, but I did not specify that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.