|
Answer» Well, am currently working a on posts and comment system using php language.... when never I comment of a post... comments tend to REPEAT on other post...
[attachment deleted by admin to conserve space]First of all, you'd be best off using a service like http://pastebin.com/ or https://gist.github.com/ to share code rather than using screenshots.
Looking at your code, you don't appear to have any sort of post ID column in your comments table. You need this so that each comment can be linked to the post that it refers to, you would then need to update the query that retrieves comments to restrict it to comments where the post ID is the ID of the post you are loading.
Also, if you are planning on actually launching this site, you need to look into preventing SQL injection and cross site scripting (XSS) attacks. XSS is where people can put HTML/Javascript code into a comment, this will then run on the PAGE for people who visit the site which can be pretty nasty, you should use a function like http://php.net/manual/en/function.htmlentities.php to sanitise any input from the user before putting it into HTML that is sent to the browser.
To prevent SQL injection you need to use a function like http://php.net/manual/en/mysqli.real-escape-string.php to escape/sanitise any input from the user before CONCATENATING it into a database query string, otherwise people can inject carefully crafted strings and manipulate database queries. You could also look at using PDO prepared statements as this would generally be the best option.http://pastebin.com/bnt9bTD2
Am aware of injection... I was just working with post & comment as the way of learn.... thank you for reminding me that!.... I'll TRY using PDO in advanced but for now I just need to solve this problem
I would be glady if you solve it for me!... Now I dd this! http://pastebin.com/0qwiNC4h
I used if statement in line 55!.... but this shows no comment... another problem encountered!
[attachment deleted by admin to conserve space]Please STOP posting links and asking us to go see what you did. Cut and paste into this thread.Not sure what you are trying to do in line 55. You're comparing the $post_id variable to the string of "comment_id".
At the moment you aren't storing which post each comment relates to in the database, it is impossible to do what you are trying to do with your current database schema. You need to change your database schema so the comment table has a post_id column then update the INSERT query to include the ID of the post that the comment relates to then update the query that gets the comments and add a WHERE clause to only get comments where the post_id column is the same as the current post ID.
Quote from: Allan on September 26, 2016, 02:17:14 PM Please stop posting links and asking us to go see what you did. Cut and paste into this thread.
To be fair it was me that suggested using pastebin. I prefer it as it gives line numbers/syntax highlighting and stops the thread getting full of massive blocks of code. However, if using code tags are preferred on here then that's fine.line 55 it was worth trying.... it tends to duplicate every comment in my database
let me work on that.. cause you're the second one telling me to do that!!... ill keep you posted it works
...My bad about pastebin linksI failed man... I would be glad if you send me some scripts that I need to work with....
|