SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Almeaty Member
    Join Date
    Jul 2000
    Location
    Nowhere
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How do I insert both into a mySQL table with the help of PHP?

    INSERT INTO table (date,user_agent) VALUES (DATETIME(), HTTP_USER_AGENT)

    doesn't work... replacing 'DATETIME' by 'DATE' doesn't work either.

  2. #2
    Freelance Web Designer KeithMcL's Avatar
    Join Date
    Oct 1999
    Location
    Dublin, Ireland
    Posts
    1,125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well i'm only new to PHP so no laughing if this is wrong

    What about replacing DATETIME is CURDATE() ??

    rgds,

  3. #3
    Almeaty Member
    Join Date
    Jul 2000
    Location
    Nowhere
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Uhh.. yes, partly. Now only the time is missing (00:00:00)

    now it appears like this: 2000-10-06 00:00:00

  4. #4
    SitePoint Zealot oodie's Avatar
    Join Date
    Jul 2000
    Location
    Misty Mountain
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Keith is right, if you want to insert current date you can use CURDATE() or NOW() (if your field type is DATETIME, NOW() will also insert current time in the format "yyyy-mm-dd hh:mm:ss"). For user agent, since you use PHP to insert data, you should use $HTTP_USER_AGENT (it's a PHP variable). Your query will be like this :

    $query = "INSERT INTO table (date,user_agent) VALUES (CURDATE(), '". $HTTP_USER_AGENT. "')";


  5. #5
    Almeaty Member
    Join Date
    Jul 2000
    Location
    Nowhere
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow! Wonderful It works just perfectly.


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
  •