• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Timestamp Issues

Dan

Bullah
NLC
I am trying to get the time to show for articles.

I have set up the field in articles table but each time I post a new article the time comes up as 0000-00-00 00:00:00
Here is the code sending the info to the database:

PHP:
<?php
include '../includes/config.php';
$insert = "INSERT INTO articles (pagetitle, content, date)
VALUES ('".$_POST['pagetitle']."', '".$_POST['content']."', '".$_POST['date']."')";
$add_data = mysql_query($insert);

?>

And here is the section on my php page that displays the articles:

PHP:
<?php
$sql = "select * from articles";
$result = mysql_query ($sql);

while ($row = mysql_fetch_array($result))
{
$field1= $row["pagetitle"];
$field2= $row["content"];
$field3= $row["date"];

echo "$field1<br>";
echo "$field3<br>";
echo "$field2<br>";

}
?>

Any ideas?
 
i personally ALWAYS use a unix timestamp for easy readability and conversion to any way i want...

PHP:
// Define current UNIX time
$current_unix_date = gmmktime();

// Convert to Readable
$converttime = date("F j Y g:i a", $current_unix_date);

// Convert Readable to UNIX
$timeStamp = strtotime($converttime);

then all you need to do is call $timeStamp when you are inserting the time in the database. convert your db cell to be varchar instead of date or time, or whatever you are using.
 
Hi Justin,

I added the code you gave to go.php and changed the database to timestamp VARCHAR(255) and also changed the call in index to timestamp.
When I post, nothing shows for the date.
 
Back
Top