Jump to content

[SOLVED] Getting edit date into database?


wwfc_barmy_army

Recommended Posts

Hello.

 

I have the following code:

 

					    <?php 

$editedtext = $_POST['edittext'];
if ($_POST['Submit']) {
$query="UPDATE text SET textblock='$editedtext', lastedit=CURDATE() WHERE textid = 3";
mysql_query($query);
echo "Record Updated";
}
?>

 

I've trying to get it so the lastedit field gets set to the date when it was last edited, but it's not entering anything, where am i going wrong?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/74863-solved-getting-edit-date-into-database/
Share on other sites

time() function would work.

 

<?php 

$editedtext = $_POST['edittext'];
if ($_POST['Submit']) {
$query=" UPDATE text SET textblock='$editedtext', lastedit='time()' WHERE textid = '3' ";
mysql_query($query) or die("I'm sorry, we encountered an error with this query.".mysql_error());
echo "Record Updated";
//print $query;
//if you echo out the query, people can see what you're doing
}
?>

<?php 

$editedtext = $_POST['edittext'];
if ($_POST['Submit']) {
$date = date("Y-m-d", time());

$query=" UPDATE text SET textblock='$editedtext', lastedit='$date' WHERE textid = '3' ";
mysql_query($query) or die("I'm sorry, we encountered an error with this query.".mysql_error());
echo "Record Updated";
//print $query;
//if you echo out the query, people can see what you're doing
}
?>

 

www.php.net/date  use that with www.php.net/time  to get the format you need.

you don't need the date format on the field. Make it an int(20) instead. This way, you can set a timestamp in there, why? A unix timestamp contains every information about that particular time. Seconds, Minutes, Hours, Day, Month, Year, Day of Week, AM/PM, and different timezones' time.

 

For the most part, a unix timestamp is the best to use for saving current time.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.