Timestamp showing, 01 january 1970... BUT shows correct after editing post. Why?

So when i add a post the timestamp doesnt work, but when i edit a post it updates it to the correct time/date.

Here is my addPost code:

addPost.php:

<?php include(‘includes.php’); ?>

<!DOCTYPE html>
	<head>
		<title>QSS - admin area</title>
		<link href='http://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'>
		<link rel="stylesheet" href="admin.css" type="text/css" media="all">
	</head>

	<body>
		<div class="wrapper">
			<span>Logged in! Welcome <?php echo $_SESSION['user']; ?></span>
			<a href="logout.php">Logout</a>
			<ul class="topnav">
				<li><a href="index.php">Home</a></li><li><a href="posts.php">Manage Posts</a></li><li><a href="cats.php">Manage Categories</a></li><li><a href="pages.php">Manage Pages</a></li>
			</ul>
			<div class="content">
				<form action="doAddPost.php" method="post">
					<label for="Postname">Name</label><br>
					<input type="text" name="PostName" /><br>
					<label for="PostAuthor">Author</label><br>
					<input type="text" name="PostAuthor" /><br>
					<label for="PostContent">Content</label><br>
					<textarea name="PostContent"></textarea><br>
					<input type="submit" value="Add" name="submit" />
				</form>
			</div>
		</div>
	</body>
	
</html>

My doAddPost.php file:

<?php
include('includes.php');

if(isset($_POST['submit'])) {
	if(isset($_POST['PostName'])) {
		if(isset($_POST['PostContent'])) {
			addPost($_POST['PostName'],$_POST['PostAuthor'],$_POST['PostContent']);
			header("Location: posts.php");
		} else {
			echo "Please enter some content!";
		}
	} else {
		echo "Please set a post name" ;
		include('addPost.php');
	}
} else {
	header("Location: addPost.php");
}

My addPost function:

function addPost($pName, $pAuthor, $pContent, $pDate) {
	$query = mysql_query("INSERT INTO posts VALUES('','$pName', '$pAuthor', '$pContent', '$pDate')") or die(mysql_error());
}

You don’t seem to be passing the fourth argument to the addPost() function, which specifies the date created. It must be defaulting inside of your database to the start of the UNIX timestamp date, which is 1st January 1970.

You could alternatively set the date created value using the NOW() function in MySQL. For greater accuracy than yyyy-mm-dd, you’ll need to set the column type to TIMESTAMP, rather than DATE (MySQL manual):


$query = mysql_query("INSERT INTO posts VALUES('','$pName', '$pAuthor', '$pContent', NOW())") or die(mysql_error());

Thank you once again sir:P