Jump to content
Killersites Forums

Post Time Issue


Danno
 Share

Recommended Posts

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
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
$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
";
echo "$field3
";
echo "$field2
";

}
?> 

 

Any ideas?

Link to comment
Share on other sites

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:

 

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:

 

$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
";
echo "$field3
";
echo "$field2
";

}
?> 

 

Any ideas?

 

Do you actually try to put in a date and not a empty value?

 

// set the default timezone to use. Available since PHP 5.1
date_default_timezone_set('GMT');
// prints something like: 2010-02-23 15:12:11
echo date('Y-m-j G:i:s');
?>

Link to comment
Share on other sites

I am trying to get MySQL to send out the date of the article and display it when the article is posted. Just like on a blog or here on the forums. Using the timestamp feature in MySQL. Also tried timedate in MySQL but that sends out the same. All zeros.

Link to comment
Share on other sites

I am trying to get MySQL to send out the date of the article and display it when the article is posted. Just like on a blog or here on the forums. Using the timestamp feature in MySQL. Also tried timedate in MySQL but that sends out the same. All zeros.

 

But you need to put in the date manually using functions, otherwise you won't get shit.

http://www.tizag.com/mysqlTutorial/mysql-date.php

Link to comment
Share on other sites

I took out the code that gave the error again.

 

Current go.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);

?>

 

Sorry guys for being such a no0b and a pain in the arse.

Link to comment
Share on other sites

I took out the code that gave the error again.

 

Current go.php

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

?>

 

Sorry guys for being such a no0b and a pain in the arse.

 

That doesnt tell us anything, show us your database and table settings. More specifically what type the row accepts where you are trying to add the date.

Link to comment
Share on other sites

Sorry. I don't speak enough jargon.

 

The DB Table:

 

CREATE TABLE IF NOT EXISTS `articles` (
 `date` datetime NOT NULL,
 `pagetitle` varchar(60) NOT NULL COMMENT 'Tes?',
 `content` text NOT NULL,
 PRIMARY KEY  (`pagetitle`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

 

The section in index.php where the info is being displayed:

 

<?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
";
echo "$field3
";
echo "$field2
";
}
?> 

 

and go.php which sends the info to the db:

 

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

 

If you need other info just tell me what you need.

Link to comment
Share on other sites

you need to add the date in this format if you are using datetime: 'YYYY-MM-DD HH:MM:SS'

 

the php code: date('Y-m-j G:i:s') will format the date into that layout and you can simply put that in. Or you can use the NOW() function within mysql to do that. Problem with the second is that it will go after server time, and if you are wanting to choose a special timezone you will need to go with formating in php and puting that in.

 

so you would have to use a query like:

 

INSERT INTO articles (date) VALUES (NOW());

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
 Share

×
×
  • Create New...