Danno Posted February 23, 2010 Report Share Posted February 23, 2010 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? Quote Link to comment Share on other sites More sharing options...
krillz Posted February 23, 2010 Report Share Posted February 23, 2010 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'); ?> Quote Link to comment Share on other sites More sharing options...
Danno Posted February 23, 2010 Author Report Share Posted February 23, 2010 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. Quote Link to comment Share on other sites More sharing options...
krillz Posted February 23, 2010 Report Share Posted February 23, 2010 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 Quote Link to comment Share on other sites More sharing options...
Danno Posted February 23, 2010 Author Report Share Posted February 23, 2010 Ok, I have added that code to go.php and when I submit the form I get this: "Column count doesn't match value count at row 1" The display still show all zeros. Quote Link to comment Share on other sites More sharing options...
falkencreative Posted February 23, 2010 Report Share Posted February 23, 2010 I have added that code to go.php and when I submit the form I get this: Post the latest code you are working with? Are you inserting the date/time in the correct format? Quote Link to comment Share on other sites More sharing options...
Danno Posted February 23, 2010 Author Report Share Posted February 23, 2010 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. Quote Link to comment Share on other sites More sharing options...
krillz Posted February 23, 2010 Report Share Posted February 23, 2010 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. Quote Link to comment Share on other sites More sharing options...
Danno Posted February 23, 2010 Author Report Share Posted February 23, 2010 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. Quote Link to comment Share on other sites More sharing options...
krillz Posted February 23, 2010 Report Share Posted February 23, 2010 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()); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.