SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Feb 2013
    Posts
    289
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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'); ?>

    Code HTML4Strict:
    <!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:

    Code PHP:
    <?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:

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

  2. #2
    SitePoint Zealot
    Join Date
    Feb 2012
    Location
    United Kingdom
    Posts
    110
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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):
    PHP Code:
    $query mysql_query("INSERT INTO posts VALUES('','$pName', '$pAuthor', '$pContent', NOW())") or die(mysql_error()); 

  3. #3
    SitePoint Addict
    Join Date
    Feb 2013
    Posts
    289
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tpunt View Post
    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):
    PHP Code:
    $query mysql_query("INSERT INTO posts VALUES('','$pName', '$pAuthor', '$pContent', NOW())") or die(mysql_error()); 
    Thank you once again sir:P


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •