Jump to content

Recommended Posts

ok i'm trying to create my own blog using php and mysql. I've been able to post and display my post, but the post do not have the correct time stamp. they all say dec. 31 1969. What have i done wrong? Let me know what part of the code you need to see or let me know what info you need.

 

Thanks!

 

 

 

Here's the form to submit:

http://www.junkdrawer.web44.net/formsubmit.html

 

and the resulting blog post:

http://www.junkdrawer.web44.net/

Link to comment
https://forums.phpfreaks.com/topic/108638-solved-blog-php-mysql-problems/
Share on other sites

It does work

 

http://ehwtf.com

 

Posted by <a href="index.php?u=<?php echo $row['username'] ?>"><?php echo $row['username'] ?></a> on <?php echo date('d/m/Y', $row['time']) . ' at ' . date('H:i:s', $row['time']) ?> GMT

 

Uses a timestamp stored in an INT column and works perfectly

Heres the code for the form submission page. Obviously something has got to be wrong. Ideally i don't want to be able to change the date and time so i want to get rid of those areas and just have input for title and content. That's a seperate issue i can solve on my own. Can anyone tell me what's wrong with the timestamp function?

 

Thanks  ;D

 

<?php
if (isset($_POST['submit'])) {
    $month = htmlspecialchars(strip_tags($_POST['month']));
    $date = date("m d Y");
    $year = htmlspecialchars(strip_tags($_POST['year']));
    $time = htmlspecialchars(strip_tags($_POST['time']));
    $title = htmlspecialchars(strip_tags($_POST['title']));
    $entry = $_POST['entry'];
    $timestamp = "strtotime($month . ” ” . $date . ” ” . $year . ” ” . $time)";
    $entry = nl2br($entry);
    if (!get_magic_quotes_gpc()) {
        $title = addslashes($title);
        $entry = addslashes($entry);
    }
    mysql_connect (DELETED FOR PRIVACY) ;
    mysql_select_db (DELETED FOR PRIVACY);
    $sql = "INSERT INTO php_blog (timestamp,title,entry) VALUES ('$timestamp','$title','$entry')";
    $result = mysql_query($sql) or print("Can’t insert into table php_blog.<br />" . $sql . "<br />" . mysql_error());
    if ($result != false) {
        print "Your entry has successfully been entered into the database.";
    }
    mysql_close();
}
?>
<?php
$current_month = date("F");
$current_date = date("d");
$current_year = date("Y");
$current_time = date("H:i");
?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

<p><strong><label for="month">Date (month, day, year):</label></strong> 

<select name="month" id="month">

<option value="<?php echo $current_month; ?>"><?php echo $current_month; ?></option>
</select>

<input type="text" name="date" id="date" size="2" value="<?php echo $current_date; ?>" />

<select name="year" id="year">
<option value="<?php echo $current_year; ?>"><?php echo $current_year; ?></option>
</select>

<strong><label for="time">Time:</label></strong> <input type="text" name="time" id="time" size="5" value="<?php echo $current_time; ?>" /></p>

<p><strong><label for="title">Title:</label></strong> <input type="text" name="title" name="title" size="40" /></p>

<p><textarea cols="80" rows="20" name="entry" id="entry"></textarea></p>

<p><input type="submit" name="submit" id="submit" value="Submit"></p>

</form>

Well i want a timestamp so that i can post multiple blog entries in a day and it will order them correctly i guess. I have 4 rows in my mySQL table that are from top to bottom id, timestamp, title, entry. The timestamp field is formatted as datetime in mySQL. When i post an entry all the fields but timestamp work. The time stamp for each entry is all zeros. So for some reason the time and date aren't posting to mySQL. Why?

 

Curtis

Actually i guess i haven't solved it. I can get it to display the correct seconds, but i don't know the code to display current hour and minute i tried H and m, but those don't work. Anyone know?

 

Edit i got the minutes right, but when i try H for hours i get 22, but it's 19 where i'm at. When i try h i get 10, but it's 7 here. How can i change it to my time? I know it must be on the servers time (which must be in the east coast).

×
×
  • 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.