Howlin1 Posted October 7, 2010 Share Posted October 7, 2010 For a website I am making for college I want to add a date and time feature for a comment form. I want the date and time to show when a user submits a comment, so a user will enter their name, email address and comments and when the comment is sent to the database I want to be able to see the time the comment was sent at.I have tried to google it, but I haven't had much success. So any help would be nice. :) Jesus Christ, can't you just admit that you're wrong? :rolleyes:Cause I'm not wrong. Link to comment Share on other sites More sharing options...
obfuscator Posted October 7, 2010 Share Posted October 7, 2010 You can retrieve the date and time via $_SERVER['REQUEST_TIME']. "It's not a rest for me, it's a rest for the weights." - Dom Mazzetti Link to comment Share on other sites More sharing options...
dsavi Posted October 7, 2010 Share Posted October 7, 2010 Something like<?php $db = mysqli_connect('address', 'user', 'password', 'db'); // Sanitize user input $comment = mysqli_real_escape_string($db, $_POST['comment']); $name= mysqli_real_escape_string($db, $_POST['name']); $email= mysqli_real_escape_string($db, $_POST['email']); $q = mysqli_query($db, "INSERT INTO comments (comment, name, email, timestamp) VALUES '" . $comment . "', '" . $name . "', '" . $email . "', NOW() )"); ?> I think that's how you do it. That script has no error handling or anything, so just use it as sort of a guide. Link to comment Share on other sites More sharing options...
Markup Posted October 8, 2010 Share Posted October 8, 2010 Following on from dsavi:http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_now Link to comment Share on other sites More sharing options...
Clooth Posted October 17, 2010 Share Posted October 17, 2010 http://us.php.net/time Best regards,Nico Link to comment Share on other sites More sharing options...
obfuscator Posted October 17, 2010 Share Posted October 17, 2010 EDIT: Don't listen to me :( "It's not a rest for me, it's a rest for the weights." - Dom Mazzetti Link to comment Share on other sites More sharing options...
Clooth Posted October 18, 2010 Share Posted October 18, 2010 Why would time() be deprecated? Best regards,Nico Link to comment Share on other sites More sharing options...
obfuscator Posted October 18, 2010 Share Posted October 18, 2010 No idea. I was getting warnings while using it though, and $_SERVER['REQUEST_TIME'] works fine :) "It's not a rest for me, it's a rest for the weights." - Dom Mazzetti Link to comment Share on other sites More sharing options...
Clooth Posted October 18, 2010 Share Posted October 18, 2010 It's not deprecated. + $_SERVER['REQUEST_TIME'] is not the same as time(), since the REQUEST_TIME variable is the timestamp of the start of the request, not the current time. There can be differences between the two. Edit: <?php sleep(5); echo 'Time: '. time() .'<br />'; echo 'Request time: '. $_SERVER['REQUEST_TIME']; Time: 1287421077Request time: 1287421072 This most likely has no effect on your type of use, but I figured I'd point it out anyway. When the accuracy wanted in the action you are saving is high, use time(). Best regards,Nico Link to comment Share on other sites More sharing options...
obfuscator Posted October 18, 2010 Share Posted October 18, 2010 Interesting. I'll try to duplicate the warning I got before and see what it actually said (I was pretty sure it said deprecated). I can't see any practical difference though as most scripts should run in such a small amount of time that they'll be the same. EDIT: From poking around a bit it seems that $_SERVER['REQUEST_TIME'] is more efficient than time(). I still don't know what the warning was, I'll check in a few hours once I get home. "It's not a rest for me, it's a rest for the weights." - Dom Mazzetti Link to comment Share on other sites More sharing options...
Clooth Posted October 18, 2010 Share Posted October 18, 2010 Was my post deleted? <_< Best regards,Nico Link to comment Share on other sites More sharing options...
obfuscator Posted October 18, 2010 Share Posted October 18, 2010 Was my post deleted? <_<Not that I can see... Anyway, I checked, and you're right. Dunno what I was thinking... "It's not a rest for me, it's a rest for the weights." - Dom Mazzetti Link to comment Share on other sites More sharing options...
Clooth Posted October 18, 2010 Share Posted October 18, 2010 Was my post deleted? <_<Not that I can see... Anyway, I checked, and you're right. Dunno what I was thinking... Hmm, I must have the reply form open at my work laptop still then. Haha :D I thought so, but it's ok, I still love you. Best regards,Nico Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now