...

View Full Version : Showing the date and time?



SMGames
07-03-2007, 08:35 AM
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 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

$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());
?>

Iszak
07-03-2007, 09:23 AM
Ok firstly you forgot to close the createdate variable marks so here is the fix for that



$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.

SMGames
07-03-2007, 10:05 AM
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

SMGames
07-03-2007, 10:27 AM
I sorta get what you mean, but where abouts in my code would i put it?

fl00d
07-03-2007, 10:47 PM
I've had this problem before. Try this


$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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum