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
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
}
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.