October 7, 201015 yr 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.
October 7, 201015 yr 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
October 7, 201015 yr 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.
October 8, 201015 yr Following on from dsavi:http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_now
October 17, 201015 yr EDIT: Don't listen to me :( "It's not a rest for me, it's a rest for the weights." - Dom Mazzetti
October 18, 201015 yr 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
October 18, 201015 yr 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
October 18, 201015 yr 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
October 18, 201015 yr 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
October 18, 201015 yr 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
Create an account or sign in to comment