oregoncurtis Posted June 4, 2008 Share Posted June 4, 2008 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 More sharing options...
stuffradio Posted June 4, 2008 Share Posted June 4, 2008 First of all this is the wrong section. All you need is: $date = date("m d Y"); Make that get inserted as the date posted. Link to comment https://forums.phpfreaks.com/topic/108638-solved-blog-php-mysql-problems/#findComment-557160 Share on other sites More sharing options...
LooieENG Posted June 4, 2008 Share Posted June 4, 2008 The way I did it, was insert time() to an INT column, and then when displaying it, I used <?php date('H:i:s', $row['time']); ?> Link to comment https://forums.phpfreaks.com/topic/108638-solved-blog-php-mysql-problems/#findComment-557577 Share on other sites More sharing options...
imdead Posted June 4, 2008 Share Posted June 4, 2008 You Don't Use A 'int' Collumn You Use 'datatime' Link to comment https://forums.phpfreaks.com/topic/108638-solved-blog-php-mysql-problems/#findComment-557613 Share on other sites More sharing options...
LooieENG Posted June 4, 2008 Share Posted June 4, 2008 But that stores it like YYYY-MM-DD, having a plain timestamp is much better IMO. Link to comment https://forums.phpfreaks.com/topic/108638-solved-blog-php-mysql-problems/#findComment-557617 Share on other sites More sharing options...
imdead Posted June 4, 2008 Share Posted June 4, 2008 Well Not If It Doesnt Work! Link to comment https://forums.phpfreaks.com/topic/108638-solved-blog-php-mysql-problems/#findComment-557626 Share on other sites More sharing options...
LooieENG Posted June 4, 2008 Share Posted June 4, 2008 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 Link to comment https://forums.phpfreaks.com/topic/108638-solved-blog-php-mysql-problems/#findComment-557637 Share on other sites More sharing options...
imdead Posted June 4, 2008 Share Posted June 4, 2008 Yeah, well if it works for that why don't you copy it then adjust it to fit your needs? Link to comment https://forums.phpfreaks.com/topic/108638-solved-blog-php-mysql-problems/#findComment-557643 Share on other sites More sharing options...
oregoncurtis Posted June 4, 2008 Author Share Posted June 4, 2008 First of all this is the wrong section. All you need is: $date = date("m d Y"); Make that get inserted as the date posted. I apologize for posting in the wrong section. Mod's please move for me. Thanks! Link to comment https://forums.phpfreaks.com/topic/108638-solved-blog-php-mysql-problems/#findComment-557851 Share on other sites More sharing options...
oregoncurtis Posted June 4, 2008 Author Share Posted June 4, 2008 Ok i'm not sure what part of th script i need to change. So could someone point me to any tutorials on building a blog with php and mySQL? Thanks, Curtis Sorry for newb post. Link to comment https://forums.phpfreaks.com/topic/108638-solved-blog-php-mysql-problems/#findComment-557853 Share on other sites More sharing options...
oregoncurtis Posted June 4, 2008 Author Share Posted June 4, 2008 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 <?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> Link to comment https://forums.phpfreaks.com/topic/108638-solved-blog-php-mysql-problems/#findComment-557864 Share on other sites More sharing options...
stuffradio Posted June 4, 2008 Share Posted June 4, 2008 You don't need to do that whole thing with your $timestamp variable. $date will suffice. Link to comment https://forums.phpfreaks.com/topic/108638-solved-blog-php-mysql-problems/#findComment-557937 Share on other sites More sharing options...
oregoncurtis Posted June 4, 2008 Author Share Posted June 4, 2008 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 Link to comment https://forums.phpfreaks.com/topic/108638-solved-blog-php-mysql-problems/#findComment-557953 Share on other sites More sharing options...
LooieENG Posted June 5, 2008 Share Posted June 5, 2008 Echo $timestamp before inserting into the database and see what value you're getting Link to comment https://forums.phpfreaks.com/topic/108638-solved-blog-php-mysql-problems/#findComment-557990 Share on other sites More sharing options...
oregoncurtis Posted June 5, 2008 Author Share Posted June 5, 2008 strtotime( . ” ” . 06 04 2008 . ” ” . . ” ” . ) So the string to time isn't working? Link to comment https://forums.phpfreaks.com/topic/108638-solved-blog-php-mysql-problems/#findComment-558031 Share on other sites More sharing options...
LooieENG Posted June 5, 2008 Share Posted June 5, 2008 <?php $date = 3; $month = 'August'; $year = 1990; $timestamp = strtotime($date . ' ' . $month . ' ' . $year); echo $timestamp; ?> Just tried that, and it gave me 649663200 Seems to work, try that. Link to comment https://forums.phpfreaks.com/topic/108638-solved-blog-php-mysql-problems/#findComment-558036 Share on other sites More sharing options...
oregoncurtis Posted June 5, 2008 Author Share Posted June 5, 2008 Thanks, but i think i might have just solved it so that the mySQL stores the time stamp in Y-m-d H:m:s format. Link to comment https://forums.phpfreaks.com/topic/108638-solved-blog-php-mysql-problems/#findComment-558037 Share on other sites More sharing options...
oregoncurtis Posted June 5, 2008 Author Share Posted June 5, 2008 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). Link to comment https://forums.phpfreaks.com/topic/108638-solved-blog-php-mysql-problems/#findComment-558039 Share on other sites More sharing options...
oregoncurtis Posted June 5, 2008 Author Share Posted June 5, 2008 SOLVED thank you everyone for your help Link to comment https://forums.phpfreaks.com/topic/108638-solved-blog-php-mysql-problems/#findComment-558043 Share on other sites More sharing options...
Recommended Posts