user1946440 user1946440 - 5 months ago 16
MySQL Question

MySql auto TIME_STAMP not working

I have created a table where I have set a column,

payment_time
, to
TIMESTAMP DEFAULT CURRENT_TIMESTAMP
while creating a table.

When I insert values I set
payment_time
to blank with
''
. However, when I checked the table on the payment_time is showing 0000-00-00 00:00:00 where I am looking for the current time. Am I making a mistake here?

Answer

try this

     payment_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP

and modify your insert statment like that

    INSERT INTO TB (`payment_time`) VALUES ('NOW()' ); 
--dont specifie the id column  it will be automatically inserted

EDIT.

 INSERT INTO TB (`col1`, `col2`,`payment_time`) VALUES ('somevalue1','somevalue2','NOW()' ); 
 -- dont use the id column just the other columns , and be sure that columns are in right ORDER

due to your edited question here is solution

INSERT INTO donors (firstName,lastName,gender,email,amount,currency)VALUES(  'MD.Borhan', 'Safa', 'm', 'borhansafa@yahoo.com', '5', 'GBP' );
Comments