Auto Add the current Date???
Hi, nice to see we're back up and running.
I have had a few problems with my sql database, (make that, with my knowledge).
Is it possible for the SQL database to automatically add the current date of when the ROW was added?
I want the date to be automatically added when the user registers. I know this is possible, as I have seen it countles times, but never actually bothered with it myself until now.
Thanks in Advance.
All the best news here: https://newsbotnet.com
DarkLight posted this at 23:40 — 10th January 2008.
He has: 287 posts
Joined: Oct 2007
Never mind... I sorted it with this:
<?php
$date=mysql_real_escape_string(date(\"F j, Y\"));
?>
then just added it to the list of values to insert into the database:
mysql_query("INSERT INTO `users` VALUES ('$fname', '$lname', '$email', '$username', '$password', '$date')");
Hope this helps anyone having the same problem.
PS< how come, I have had this problem for days, and now I have posted, I sort it??? Wierd huh?
All the best news here: https://newsbotnet.com
kazimmerman posted this at 01:06 — 11th January 2008.
He has: 698 posts
Joined: Jul 2005
I would like to suggest, if maybe even just for the future...
If you aren't already, I would suggest that the DATE column is set as one of the DATETIME, TIMESTAMP, etc field types so you can format them upon selecting them from the table. This way you are not stuck with the format that was entered when the data was inserted, but you still have all the data for the timestamp. How much sense doesn't that make?
Kurtis
JeevesBond posted this at 15:17 — 11th January 2008.
He has: 3,956 posts
Joined: Jun 2002
Also, if you use the correct date format in MySQL it'll make indexing easier. You'll probably want to ORDER BY that field at some point.
DarkLight posted this at 20:35 — 11th January 2008.
He has: 287 posts
Joined: Oct 2007
Oh, right, yes you are right, I will be needing to order them, very soon actually. I have it set to VARCHAR, I will set it to TIMESTAMP. Thanks for your advice.
Glad to see you fixed drupal, I started building www.pcgeniusproductions.com with that cms, but found I could do better things manually, so I stick to good old direct PHP/HTML coding.
I will probably be using Drupal for my education section. Probaby for the webmaster resources and things like that. Things that don't require much templating.
Thanks again, and good luck with future ideas. Give my compliments to Megan, and as you're already here, Special thanks to JeevesBond for producing an excellent service.
All the best news here: https://newsbotnet.com
JeevesBond posted this at 20:45 — 11th January 2008.
He has: 3,956 posts
Joined: Jun 2002
Makes sense, particularly if you're learning PHP, nothing like learning an extra API to add confusion.
No worries, I'll pass that on. Thanks.
a Padded Cell our articles site!
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.