Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 9th, 2003, 02:27 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
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.
Reply With Quote
  #2 (permalink)  
Old July 9th, 2003, 04:08 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
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/
Reply With Quote
  #3 (permalink)  
Old July 9th, 2003, 04:15 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:24 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.