SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast Mr Toner's Avatar
    Join Date
    Sep 2003
    Location
    Southern California, USA
    Posts
    78
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool Timestamp Not Updating

    Got me a table with a field that should contain the date & time the record was inserted/updated:

    Code:
    CREATE TABLE `ae_users` (
      `location` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
      `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
      `item_name` tinytext COLLATE utf8_unicode_ci NOT NULL,
      `item_cost` decimal(10,0) NOT NULL,
      `item_percent` decimal(10,0) NOT NULL,
      PRIMARY KEY (`location`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
    However, the value for last_updated is "0000-00-00 00:00:00" after this query is run:

    PHP Code:
    $query sprintf("INSERT INTO ae_users (location,last_update,item_name,item_cost,item_percent) 
       VALUES ('%s','%d','%s','%d','%d')
       ON DUPLICATE KEY UPDATE item_name=VALUES(item_name),item_cost=VALUES(item_cost),item_percent=VALUES(item_percent)"
    ,
       
    mysql_real_escape_string($listing$dbh),
       
    time(),
       
    mysql_real_escape_string($item_name$dbh),
       
    mysql_real_escape_string($item_cost$dbh),
       
    mysql_real_escape_string($item_percent$dbh)); 
    Same result for insert or update. Server version is 5.1.52. Any suggestions why last_updated doesn't show the current timestamp?

  2. #2
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    drop last update from the insert entirely, it will still update.

  3. #3
    SitePoint Enthusiast Mr Toner's Avatar
    Join Date
    Sep 2003
    Location
    Southern California, USA
    Posts
    78
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, that's right. Seems having that there was causing (probably) an illegal value that was changed to "zero." Thanks for the second set of eyes! Congrats on 1500 posts, too!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •