Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/49285-date-doesnt-display-why/
Share on other sites

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

 

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

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

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

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

 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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