Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Showing the date and time?

    Can anyone help me, i am trying to insert the date and time into a table, so when someone registers it shows the date and time or when they register.

    This is my insert code:
    PHP Code:
    <?php session_start(); ?>
    <?php 

    $username
    ="****";
    $password="****";
    $database="****";

    mysql_connect('************',$username,$password);
    @
    mysql_select_db($database) or die("Unable to select database");

    $loginname=$_POST['loginname']; 
    $password=$_POST['password'];
    $createdate=$_POST['createdate']; 
    $name=$_POST['name'];
    $age=$_POST['age'];
    $location=$_POST['location'];
    $description=$_POST['description'];
    $email=$_POST['email'];
    $warn=0;
    $noblog="This user has not created a page yet";

    $query="INSERT INTO users (
    loginname, 
    password,
    createdate
    name, 
    age, 
    location, 
    description, 
    email, 
    warn) 

    VALUES (
    '$loginname', 
    '$password',
    '$createdate
    '$name', 
    '$age', 
    '$location', 
    '$description', 
    '$email', 
    '$warn'

    )"

     
    $result=mysql_query($query);
    ?>
    At the moment it shows 0000-00-00 along with the username, password etc. Can anyone show me how to show the date and time of when they registerd

    Just if you need it, this is the code that i userd to create my users trable:
    PHP Code:
    <?php

    $username
    ="*****";
    $password="*****";
    $database="*****";

    mysql_connect('***********',$username,$password);
    @
    mysql_select_db($database) or die("Unable to select database");

    $query="CREATE TABLE users(

    id          INT           NOT NULL    AUTO_INCREMENT,
    createdate  DATE          NOT NULL,
    loginname   VARCHAR(20)   NOT NULL,
    password    VARCHAR(20)   NOT NULL,
    name        VARCHAR(40),
    age         INT(2),
    location    VARCHAR(40),
    description CHAR(255),
    email       VARCHAR(40)   NOT NULL,
    warn        INT,

    PRIMARY KEY(id))"
    ;
    $result=mysql_query($query) or die(mysql_error());
    ?>
    http://www.smgames.staticfire.co.uk Under construction, Currently hiring mods and admins anyone interested pm me.

  • #2
    Regular Coder Iszak's Avatar
    Join Date
    Jun 2007
    Location
    Perth, Western Australia
    Posts
    332
    Thanks
    2
    Thanked 58 Times in 57 Posts
    Ok firstly you forgot to close the createdate variable marks so here is the fix for that

    PHP Code:
    $query="INSERT INTO users (
    loginname, 
    password,
    createdate
    name, 
    age, 
    location, 
    description, 
    email, 
    warn) 

    VALUES (
    '$loginname', 
    '$password',
    '$createdate'
    '$name', 
    '$age', 
    '$location', 
    '$description', 
    '$email', 
    '$warn'

    )"

    Secondly.. all the DATE type does is extract date part of the date or datetime expression. eg.

    mysql> SELECT DATE('2003-12-31 01:02:03');
    -> '2003-12-31'

    So it may be your input, you can simply make it a VARCHAR and use PHP date and insert the information the way you want it eg. 3/7/07 4:23 PM but otherwise.. I don't know what you're doing wrong.

  • #3
    New Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The first problem you pointed out is actually correct on my server, i just copied it wrong, also is there away where it automaticaly shows the date the moment you press the register buttom, i want it so the users dont write the date they joined. Other wise i dont know what you are on about, please explain
    http://www.smgames.staticfire.co.uk Under construction, Currently hiring mods and admins anyone interested pm me.

  • #4
    New Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I sorta get what you mean, but where abouts in my code would i put it?
    http://www.smgames.staticfire.co.uk Under construction, Currently hiring mods and admins anyone interested pm me.

  • #5
    Regular Coder
    Join Date
    Mar 2007
    Location
    Quebec
    Posts
    261
    Thanks
    6
    Thanked 7 Times in 7 Posts
    I've had this problem before. Try this

    PHP Code:
    $createdate=date(y.m.d); 
    I believe for MySQL, the date has to be set in that specific order. Year, month, day.

    By the way, you don't need a field to input the date, if that was what was confusing you in the previous post.


  •  

    Posting Permissions

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