can you date stamp an database entry

Discussion in 'PHP' started by dougvcd, Jul 26, 2008.

  1. #1
    is it possable that when a member registers on my web site it puts a date in a field in database
    cheers
    Doug
     
    dougvcd, Jul 26, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Yes, it's possible.
     
    nico_swd, Jul 26, 2008 IP
  3. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    cheers for that reply
    any clues how to do it
    cheers
    Doug
     
    dougvcd, Jul 26, 2008 IP
  4. 2slick

    2slick Peon

    Messages:
    73
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    if you are using MySQL, define a field that is timestamp type.
     
    2slick, Jul 26, 2008 IP
  5. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    cheers
    i made a new field in database and called it date set it to time stamp
    whent back to web page made an entry then went back to database to look and nothing there except zeros
    do i have to put some more code some where
    cheers
    Doug
    i thought it did it auto
     
    dougvcd, Jul 26, 2008 IP
  6. pubdomainshost.com

    pubdomainshost.com Peon

    Messages:
    1,277
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Here is a sample from the web, hope this helps.
    ***********************************************************
    <?php
    //This assumes you have created table named date & datetime in your database
    //Connect to DB
    echo "For Table Date Type Date";
    $query_manual = "INSERT INTO date (type, date) VALUES ('DATE: Manual Date', '2008-7-26')";
    $query_auto = "INSERT INTO date(type, date) VALUE ('DATE: Auto CURDATE()', CURDATE() )";

    mysql_query($query_manual) or die(mysql_error());
    mysql_query($query_auto) or die(mysql_error());

    echo "For Table datetime Type Datetime";
    $query_auto = "INSERT INTO datetime(type, datetime) VALUE ('DATE: Manual CURDATE()', CURDATE() )";
    $query_auto = "INSERT INTO datetime(type, datetime) VALUE ('DATE: Auto NOW()', NOW() )";

    mysql_query($query_manual) or die(mysql_error());
    mysql_query($query_auto) or die(mysql_error());

    ?>
    ************************************************************
    HTH,
    GS

    Keep going Doug :) Appreciate your spirit
    Age is nothing but a fictitious notion of time
     
    pubdomainshost.com, Jul 26, 2008 IP
  7. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    this is what i have done put this line on regform
    <input type="hidden" name="date" value="('DATE: Auto CURDATE()', CURDATE() )">
    PHP:
    and this on add form
    $date=$_POST['date'];
    PHP:
    with this in the insert
    '$date'
    PHP:
    cheers
    Doug
     
    dougvcd, Jul 26, 2008 IP
  8. GreatMetro

    GreatMetro Peon

    Messages:
    117
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Typically, I just have a field in my table called dt_stamp [data type : int(10) because the number of seconds since the Unix Epoch is still in the 10 digit range]

    Then in my PHP I create a variable:

    $sql_dt_stamp = time();

    insert into table (dt_stamp) values ($sql_dt_stamp);

    By keeping it as a simple integer, you can do whatever you want with it down the road, as the PHP function date() accepts the Unix Epoch value, and since it's an integer, it's sortable.

    Just another way of doing it, maybe not the best, but it has always worked for me.
     
    GreatMetro, Jul 27, 2008 IP
  9. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #9
    This is a terrible idea. The user could modify the date and submit something else...


    Why not just put the date stuff directly in the query string, so the user has no access to it?
     
    nico_swd, Jul 27, 2008 IP
  10. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #10
    yes i would like that but havnt got any idea how
    cheers
    Doug
     
    dougvcd, Jul 27, 2008 IP
  11. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #11
    Take a look at pubdomainshost.com's example. Or post your code so we can help.
     
    nico_swd, Jul 27, 2008 IP
  12. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #12
    this is the code i use for insert
    mysql_query("INSERT INTO `members` VALUES ('$id', '$region', '$name', '$username', '$password', '$email', '$contact' , '$parkname', '$county', '$parklocation', '$make', '$caravandetails', '$smoke', '$pets', '$kids', '$sex', '$pname', '$enq', '$date')");
    PHP:
    so where would i put this code
    auto = "INSERT INTO date(type, date) VALUE ('DATE: Auto CURDATE()', CURDATE() )";
    PHP:
    cheers
    Doug
     
    dougvcd, Jul 27, 2008 IP
  13. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #13
    ok have sorted it out it was so simple all i had to do was add this line
    $date = date("d-m-Y");
    PHP:
    does just what i wanted it to
    cheers for all the help
    Doug
     
    dougvcd, Jul 27, 2008 IP
  14. xlcho

    xlcho Guest

    Messages:
    532
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Why writting the date with php ? Just use SQL's NOW() function. Best thing to do is have the date field created with something like that:
    date date NOT NULL DEFAULT NOW()
    Code (markup):
    and you'll never even have to insert values in this field. Just insert the other values and don't bother even listing the 'date' column in you INSERT query, it will automatically get the current date.
     
    xlcho, Jul 27, 2008 IP
  15. Submerged

    Submerged Active Member

    Messages:
    132
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #15
    Dang, xlcho, I didn't know about that. Thanks!
     
    Submerged, Jul 27, 2008 IP
  16. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #16
    use NOW() on datetime data type table column

    use CURDATE() on date data type table column

    If you use date data type then your query will look like this.

    "INSERT INTO tablename(name,today) VALUES('Finau',CURDATE())";

    if you use datetime data type then your query will look like this.

    "INSERT INTO tablename(name,login_time) VALUES('Finau',NOW())";
     
    php-lover, Jul 27, 2008 IP