Re: [PHP] adding the date to a database

2001-07-18 Thread Christopher Ostmo

Brad Wright pressed the little lettered thingies in this order...

> Hi, 
> I have a database with a 'date' field. What is the syntax for using the
> (mysql) function 'getdate()', to insert the date into the DB table.
> the syntax I'm currently using is:
> $query = "Insert INTO visits (visName, date)
> values ('$name', getdate()) " ;
> $result = mysql_query($query, $db);
> 

If you're using MySQL 3.23 (or newer) and the field is one of the date, 
time or datetime types, use NOW()

For example:
$query = "Insert INTO visits (visName, date)
values ('$name', NOW()) " ;

This returns a "-MM-DD HH:MM:SS" string that MySQL will 
automatically convert to any of the date/time field types.

Christopher Ostmo
a.k.a. [EMAIL PROTECTED]
AppIdeas.com
Innovative Application Ideas
Meeting cutting edge dynamic
web site needs since the 
dawn of Internet time (1995)

For a good time,
http://www.AppIdeas.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] adding the date to a database

2001-07-18 Thread Don Read


On 18-Jul-2001 Brad Wright wrote:
> Hi, 
> I have a database with a 'date' field. What is the syntax for using the
> (mysql) function 'getdate()', to insert the date into the DB table.
> the syntax I'm currently using is:
> $query = "Insert INTO visits (visName, date)
> values ('$name', getdate()) " ;
> $result = mysql_query($query, $db);
> 
> This does not work (but returns no errors) ie, nothing inserted into the
> database.
> 

did you test $result ?

It's usually helpful to check the manual when you're not sure of the syntax
for MySQL you can use NOW() , CURDATE(), or CURRENT_DATE.


-- 
Don Read   [EMAIL PROTECTED]
-- It's always darkest before the dawn. So if you are going to 
   steal the neighbor's newspaper, that's the time to do it.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]