Jump to content

Adding dates to mysql


nuttycoder

Recommended Posts

Hi I am trying to auto date dates into the database with every entry but so far all can  get is 0000-00-00 00:00:00 using datetime data type.

 

Here is my code for inserting into the databse

 

if(isset($_POST['Submit']))
{
   $newsTitle   = $_POST['newsTitle'];
   $newsCont = $_POST['newsCont'];
     
   if(!get_magic_quotes_gpc())
   {
      $newsTitle   = addslashes($newsTitle);
      $newsCont = addslashes($newsCont);
   
   }
   
   
   $query = " INSERT INTO news (newsTitle, newsCont, newsDate) VALUES
   ('$newsTitle', '$newsCont', '$newsDate')";
   
   mysql_query($query) or die('Error ,query failed');

   echo "'$newsTitle' added";
}
?>

<table width="71%" border="0" align="center">
  <tr>
    <td>

<form  method="post" action="insert-news.php">
<input type="hidden" name="newsID" value="<?=$newsID;?>">
<p>News Title <br />
<input name="newsTitle" type="text" size="40" maxlength="255" >
<br />
<br />
News Content<br />
<textarea name="newsCont" cols="80" rows="15" id="newsCont"></textarea>
<input type="hidden" name="newsDate" value="<?=$newsDate;?>">
<br />
<input type="submit" name="Submit" value="Add News">
</p>
<p align="center"><a href="../stories">Back to Admin</a></p>
</form>
</td>
  </tr>
</table>

 

Any help on guide me where am going wrong would be great

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/58847-adding-dates-to-mysql/
Share on other sites

 

I have changed my table structue to use timestamp and have changed my sql query to match

 

<?php
$query = "INSERT INTO news (newsTitle, newsCont, newsDate, timestampColumn) 
   VALUES ('$newsTitle', '$newsCont', '$newsDate',NOW())";
?>

 

but now the request just fails.

 

 

Link to comment
https://forums.phpfreaks.com/topic/58847-adding-dates-to-mysql/#findComment-292016
Share on other sites

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.