Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 9th, 2003, 02:27 PM
Authorized User
 
Join Date: Jul 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default time() and INSERT

Can someone tell me what I'm doing wrong:

$time = time();
$sql = "INSERT INTO articles (title, description, bodyText, created) VALUES ('$new_title', '$new_description', '$new_bodyText', '$time')";
$result = mysql_query($sql);

It all seems to work OK but my "created" field has "0000-00-00 00:00:00" instead of the current time.

Thanks for any pointers.
 
Old July 9th, 2003, 04:08 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What's the data type of your 'created' column? If it's not an integer or unix timestamp, you can't just insert an integer into it.

You need to convert the unix timestamp into a the DATETIME format that MySQL expects (the "0000-00-00 00:00:00" looks like DATETIME to me...)

You can do this using either PHP *or* MySQL.

PHP:
$datetime = date("Y-m-d H:i:s", time());
$sql = "INSERT INTO articles
           (title, description, bodyText, created)
        VALUES
           ('$new_title', '$new_desc', '$new_bodyText', '$datetime')";

MySQL:
$time = time();
$sql = "INSERT INTO articles
           (title, description, bodyText, created)
        VALUES
           ('$new_title', '$new_desc', '$new_bodyText',
            FROM_UNIXTIME($time))";

For more info, read the manuals:
  http://www.php.net/date
  http://www.mysql.com/doc/en/Date_and...functions.html


Take care,

Nik
http://www.bigaction.org/
 
Old July 9th, 2003, 04:15 PM
Authorized User
 
Join Date: Jul 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Nikolai - that's what I've been doing wrong!





Similar Threads
Thread Thread Starter Forum Replies Last Post
INSERT Multiple rows to database at one time melkin Classic ASP Databases 19 April 11th, 2007 08:22 AM
store insert/update date/time stamp in sql2k db alexdcosta ASP.NET 2.0 Basics 0 June 22nd, 2006 05:44 AM
How i can insert specific delay time in microsseco eakkaluck Visual C++ 1 November 2nd, 2005 05:52 PM
Time & date insert and display in myql/asp page karib MySQL 3 June 30th, 2004 05:29 AM
Time out on insert query Tom_Nguyen SQL Server 2000 0 June 29th, 2003 11:23 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.