Tekforums

Chat => Entertainment & Technology => Topic started by: addictweb on April 29, 2007, 14:31:13 PM

Title: How to ... store user comments?
Post by: addictweb on April 29, 2007, 14:31:13 PM
I want to add an image upload feature to my site so that people can upload their own images. I also want people to be able to rank and comment on images.

Whats the best way of storing this data? Im competent with PHP and MySQL but i cant thing of the form it would take in the database.

Cheers for any help.
Title: How to ... store user comments?
Post by: M3ta7h3ad on April 30, 2007, 15:04:58 PM
images can either be stored in the database, or can be stored as just paths in the database.

If this is the case, then just link the comments to the image address by using a foreign key.

So..

Images(imageID,imagepath,...)
Comments(commentID,comment,FK_imageID,FK_userID)
Users(userID,username,password,...)

That way images are linked to comments are linked to users. :)

FK_ denotes a foreign key.
Title: Re:How to ... store user comments?
Post by: Rivkid on May 01, 2007, 09:56:56 AM
I used to just use coppermine - it was easier! :D
Title: How to ... store user comments?
Post by: Sweenster on May 01, 2007, 10:15:11 AM
if you are doing this i would also be very careful how you process what people put in comments, very easy to bugger a system if you can put any code you want on.

basically strip all tags

tis why bbcode is used rather than full html
Title: Re:How to ... store user comments?
Post by: addictweb on May 01, 2007, 16:17:58 PM
Cheers for the pointers guys, sounds like i have a plan of action now.

 :-)
Title: How to ... store user comments?
Post by: M3ta7h3ad on May 01, 2007, 23:45:46 PM
Quote from: Sweensterif you are doing this i would also be very careful how you process what people put in comments, very easy to bugger a system if you can put any code you want on.

basically strip all tags

tis why bbcode is used rather than full html

Rather than just that

Use.

removeslashes(striptags(trim(mysql_real_escape_string($string))));

that way, if magic_quotes is on you dont double escape characters.

Whitespace from the leading and trailing edge is cleaned up.

all html tags are stripped

and any mysql characters are escaped, thus preventing mysql injection attacks.
Title: Re:How to ... store user comments?
Post by: madmax on May 01, 2007, 23:55:26 PM
properly coded stored procedures = no injection attacks
Title: Re:How to ... store user comments?
Post by: M3ta7h3ad on May 02, 2007, 03:49:23 AM
Quote from: madmaxproperly coded stored procedures = no injection attacks

Does MySQL allow the coding of stored procedures? must do I guess, but how do you write them? phpMyAdmin (the only access I have to my mysql server) doesnt have any easy way of managing them at least as far as I can see. Sure I can write a random bit of sql and get it to run that, but seems a bit of an oversight to leave such a simple thing out of an interface that has had years to be refined.

Plus... the guy wants to make a quicky website with a gallery I think. No need for stored procedures when a few PHP functions will deal with the issue nicely.

Title: How to ... store user comments?
Post by: cornet on May 04, 2007, 01:50:24 AM
MySQL does stored procedures as of 5.0

use prepare and execute statements, that will avoid most injection attempts.

Cornet
Title: How to ... store user comments?
Post by: Sam on May 06, 2007, 13:30:02 PM
Or use a proper language that has a well specced API that disallows any injection attacks. PHP is not suitable for Enterprise apps.
Title: How to ... store user comments?
Post by: M3ta7h3ad on May 06, 2007, 14:05:01 PM
Quote from: SamOr use a proper language that has a well specced API that disallows any injection attacks. PHP is not suitable for Enterprise apps.

JAVA and JDBC I love, but if all the lad wants is a quickie image gallery with comments... then its a wee overkill.