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
Share on other sites

Eh... NOW() is a MySQL function.  And don't put it in the form; put it in the code that inserts the row.

 

<?php

$query = "INSERT INTO news (newsTitle, newsCont, newsDate, timeStampColumn) VALUES ('$newsTitle', '$newsCont', '$newsDate',NOW())";

?>

Link to comment
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
Share on other sites

Have you checked for errors?  If so, what are they?

 

<?php

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

mysql_query($query) or die(mysql_error() . "<br />\nQuery: $query");

?>

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.