automaicly add the sign up date in phpmyadmin when join.

Discussion in 'Programming' started by ScottDB, May 27, 2011.

  1. #1
    Hi all. I am just learning this stuff and have created a simple site and can pull information from the database and onto the page. I can also create forms and add to the data base. I'm stuck on how to get the sign up date to apear on the database for me to pull the info from. Can someone direct me to a good tutorial or can give me the code. I tried to read up on it through google search but can't find the code. I think it is called a time stamp. Is this correct?
     
    ScottDB, May 27, 2011 IP
  2. TSelbeck

    TSelbeck Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hey Scott,

    MySQL actually has a field, I believe is called Timestamp. On there, is an option which is something like 'current timestamp' (it's a checkbox IIRC). It will automatically insert the current time when you add an entry. I've never liked this option, though. I find it a little difficult to work with when querying the database.

    Another method (and one which I use), is to simply insert time() as the field value when adding the row to the database :)
     
    TSelbeck, May 28, 2011 IP
  3. ScottDB

    ScottDB Greenhorn

    Messages:
    95
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    Thanks for the reply. I have been trying everything to get this to work but nothing. I have member_since in a field value for new row upon sign up. I have datetime in type and have set the function to currentdate. It shows the callender and date under value but it just stays at 0000.

    How did you get yours set up to work?
     
    ScottDB, May 28, 2011 IP
  4. thejimy

    thejimy Greenhorn

    Messages:
    9
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    13
    #4
    You can do it with two different ways:

    1) Set your member_since field to be of type "TIMESTAMP" and set it's default value to "CURRENT_TIMESTAMP". Whenever a new entry is created, your field member_since will have the current timestamp inserted into it. Make sure though, you don't include this field in your INSERT query with any value, as it won't be updated with the default value which is the CURRENT_TIMESTAMP, but with the value you have in your INSERT query instead. If you need to update already existing fields, you need to do something like "UPDATE table SET member_since = NOW()". Keep in mind though, that this isn't going to work with another field that you would have set the attribute to UPDATE TIMESTAMP when a row gets modified.

    2) A approach more preferred by many is, to set the type of member_since to DATETIME and whenever you insert a new account, set the value of the field by using the function NOW(). When having two example fields like member_name and member_password, this could look something like "INSERT INTO table (member_name, member_password, member_since) VALUES ('membername', 'password', NOW())".

    Both methods actually work and more often it's a personal preference which one you select.
     
    thejimy, May 29, 2011 IP