Click here to Skip to main content
15,860,861 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi frnds,

how to insert date and time in this sql query

SQL
mysql_query("INSERT INTO contacts(
               firstname,
               lastname,
               email,
               telephone,datetime
               )VALUES(
                   '".mysql_real_escape_string($data[0])."',
                   '".mysql_real_escape_string($data[1])."',
                   '".mysql_real_escape_string($data[2])."',
                   '".mysql_real_escape_string($data[3])."',
                   '".mysql_real_escape_string($data[4])."'
               )")or die(mysql_error());
Posted
Updated 15-Dec-13 11:27am
v4
Comments
Peter Leow 14-Dec-13 3:49am    
Does the contacts table have a datetime field?
Arun-23 14-Dec-13 3:58am    
yeah date_time

1 solution

The contacts table must have a datetime field first.

Change the last entry in the values

SQL
'".mysql_real_escape_string($data[4])."'


to

NOW()
 
Share this answer
 
v4
Comments
Arun-23 14-Dec-13 4:22am    
updated now how to get current date and time
Peter Leow 14-Dec-13 4:38am    
Edited solution. Use now() in mysql to get the current date time.

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