foevah Posted April 30, 2007 Share Posted April 30, 2007 Hi everyone I made a PHP blog that uploads an image into the db at the same time with a text entry. This worked fine until I tried adding the timestamp to the entries and everything stopped working? ??? The blog entry form phps can be viewed here: http://www.webdesignhull.lincoln.ac.uk/jecgardner/blog_test2/entry/uploader_help.phps The index phps can be seen here: http://www.webdesignhull.lincoln.ac.uk/jecgardner/blog_test2/entry/index_help.phps Please can someone help! Quote Link to comment https://forums.phpfreaks.com/topic/49285-date-doesnt-display-why/ Share on other sites More sharing options...
Dragen Posted April 30, 2007 Share Posted April 30, 2007 what do you mean by 'stopped working'? do you recieve an error? or does it display something strange.. or even nothing at all? Quote Link to comment https://forums.phpfreaks.com/topic/49285-date-doesnt-display-why/#findComment-241489 Share on other sites More sharing options...
foevah Posted April 30, 2007 Author Share Posted April 30, 2007 I get this error in the browser: Can't insert into table php_blog. INSERT INTO php_blog (timestamp,title,entry,password,image) VALUES (now()'1177930320','date working','working date','0','cap_small.jpg') You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ''1177930320','date working','working date','0','cap_small.jpg')' at Warning: Cannot modify header information - headers already sent by (output started at /home/hullweb/public_html/jecgardner/blog_test2/entry/uploader_vege.php:134) in /home/hullweb/public_html/jecgardner/blog_test2/entry/uploader_vege.php on line 18 Warning: Cannot modify header information - headers already sent by (output started at /home/hullweb/public_html/jecgardner/blog_test2/entry/uploader_vege.php:134) in /home/hullweb/public_html/jecgardner/blog_test2/entry/uploader_vege.php on line 12 Warning: Cannot modify header information - headers already sent by (output started at /home/hullweb/public_html/jecgardner/blog_test2/entry/uploader_vege.php:134) in /home/hullweb/public_html/jecgardner/blog_test2/entry/uploader_vege.php on line 138 I added the PHP code below on the index page at the end of the while loop and this is what it returns: 'dateAdded' => NULL, : var_export($row); Quote Link to comment https://forums.phpfreaks.com/topic/49285-date-doesnt-display-why/#findComment-241493 Share on other sites More sharing options...
AndyB Posted April 30, 2007 Share Posted April 30, 2007 INSERT INTO php_blog (timestamp,title,entry,password,image) VALUES (now()'1177930320','date working','working date','0','cap_small.jpg') Look at the query. Remove '117 ...320' . Your query construction code is wrong. Quote Link to comment https://forums.phpfreaks.com/topic/49285-date-doesnt-display-why/#findComment-241494 Share on other sites More sharing options...
Dragen Posted April 30, 2007 Share Posted April 30, 2007 well I'd say it's something to do with this bit: VALUES (now()'1177930320','date working','working date','0','cap_small.jpg') I think the now() part is incorrect.. I'm not sure what it's there for, but all values to insert should be enclosed in '. try VALUES ('now()1177930320','date working','working date','0','cap_small.jpg') Quote Link to comment https://forums.phpfreaks.com/topic/49285-date-doesnt-display-why/#findComment-241495 Share on other sites More sharing options...
foevah Posted April 30, 2007 Author Share Posted April 30, 2007 This is what the index page displays: http://www.webdesignhull.lincoln.ac.uk/jecgardner/blog_test2/index_vege.php?page=3 I changed the SQL line on the uploader page to: $sql = "INSERT INTO php_blog (timestamp,title,entry,password,image) VALUES ('now()','$title','$entry','$password','$new_name')"; On the index page it says: 'dateAdded' => NULL, Why doesnt the date display ??? I have uploaded the new phps file http://www.webdesignhull.lincoln.ac.uk/jecgardner/blog_test2/entry/uploader_help.phps Quote Link to comment https://forums.phpfreaks.com/topic/49285-date-doesnt-display-why/#findComment-241506 Share on other sites More sharing options...
obsidian Posted April 30, 2007 Share Posted April 30, 2007 I changed the SQL line on the uploader page to: $sql = "INSERT INTO php_blog (timestamp,title,entry,password,image) VALUES ('now()','$title','$entry','$password','$new_name')"; Why doesnt the date display ??? Because the NOW() function is not a string. You need to actually call the NOW() function for SQL to execute: INSERT INTO php_blog (timestamp, title, entry, password, image) VALUES (NOW(), '$title','$entry','$password','$new_name') Quote Link to comment https://forums.phpfreaks.com/topic/49285-date-doesnt-display-why/#findComment-241508 Share on other sites More sharing options...
foevah Posted April 30, 2007 Author Share Posted April 30, 2007 I had that before I made it a string.. It still shows this on the index page: 'dateAdded' => NULL, Quote Link to comment https://forums.phpfreaks.com/topic/49285-date-doesnt-display-why/#findComment-241512 Share on other sites More sharing options...
obsidian Posted April 30, 2007 Share Posted April 30, 2007 I had that before I made it a string.. It still shows this on the index page: 'dateAdded' => NULL, What datatype is the timestamp column? How is it attempting to be displayed (PHP code)? Quote Link to comment https://forums.phpfreaks.com/topic/49285-date-doesnt-display-why/#findComment-241517 Share on other sites More sharing options...
foevah Posted April 30, 2007 Author Share Posted April 30, 2007 This is the timestamp column: timestamp int(20) NOT NULL, I have uploaded the index PHPS page that I am trying to get it to display on here: http://www.webdesignhull.lincoln.ac.uk/jecgardner/blog_test2/index_help.phps I added var_export($row); on line 207 Quote Link to comment https://forums.phpfreaks.com/topic/49285-date-doesnt-display-why/#findComment-241521 Share on other sites More sharing options...
Gobbo Posted April 30, 2007 Share Posted April 30, 2007 You can't just call it timestamp, you have to actually declare that it should be time: timestamp timestamp(14) NOT NULL Quote Link to comment https://forums.phpfreaks.com/topic/49285-date-doesnt-display-why/#findComment-241531 Share on other sites More sharing options...
foevah Posted April 30, 2007 Author Share Posted April 30, 2007 how can I modify timestamp timestamp(14) NOT NULL in the database table without deleting everything? Quote Link to comment https://forums.phpfreaks.com/topic/49285-date-doesnt-display-why/#findComment-241536 Share on other sites More sharing options...
Gobbo Posted April 30, 2007 Share Posted April 30, 2007 If you are using phpmyadmin, you should be able to click 'change' and change it like that, or you can query the database with a command like this: ALTER TABLE `database`.`table` CHANGE `column` `column` TIMESTAMP NOT NULL Quote Link to comment https://forums.phpfreaks.com/topic/49285-date-doesnt-display-why/#findComment-241543 Share on other sites More sharing options...
foevah Posted April 30, 2007 Author Share Posted April 30, 2007 I found this code but I havent tried it yet.. Please can you tell me if it is correct: $sql = "ALTER TABLE `php_blog` MODIFY `timestamp` VARCHAR '14' NOT NULL"; Quote Link to comment https://forums.phpfreaks.com/topic/49285-date-doesnt-display-why/#findComment-241544 Share on other sites More sharing options...
foevah Posted April 30, 2007 Author Share Posted April 30, 2007 Ok this sql line modified the timestamp: $sql = "ALTER TABLE `php_blog` MODIFY `timestamp` TIMESTAMP(14) NOT NULL"; it now shows 'dateAdded' => '0.00.0000', on the index page Any ideas why the db row is empty? Quote Link to comment https://forums.phpfreaks.com/topic/49285-date-doesnt-display-why/#findComment-241548 Share on other sites More sharing options...
foevah Posted April 30, 2007 Author Share Posted April 30, 2007 Ok now I am trying to display the date using this code on the index page: echo "<br /><br />".showinweb($row['dateAdded']); It is not showing? I have changed dateAdded to timestamp but still no luck.. I also have a HR and Leave Comments that should appear after each entry but they appear on the last entry on each page. Please look at my index page to see what I mean: http://www.webdesignhull.lincoln.ac.uk/jecgardner/blog_test2/index_vege.php?page=1 Any ideas how to get the date to display and get the HR / Leave a comment to show after each entry please? This is the code on my index page: http://www.webdesignhull.lincoln.ac.uk/jecgardner/blog_test2/index_help.phps Quote Link to comment https://forums.phpfreaks.com/topic/49285-date-doesnt-display-why/#findComment-241555 Share on other sites More sharing options...
obsidian Posted April 30, 2007 Share Posted April 30, 2007 You can't just call it timestamp, you have to actually declare that it should be time: timestamp timestamp(14) NOT NULL He wasn't using a nondefined timestamp... Based on his previous comment, he was using the integer data type, which in turn means you have to use the UNIX timestamp to store the data. This would entail using one of the PHP timestamp functions (such as time()) to store it. Quote Link to comment https://forums.phpfreaks.com/topic/49285-date-doesnt-display-why/#findComment-241568 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.