Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7784829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:09:28+00:00 2026-06-01T20:09:28+00:00

I have a problem with a comment system. Adding comments works, and the MySql

  • 0

I have a problem with a comment system. Adding comments works, and the MySql table shows the correct comments that have been submitted. However, when echoing the contents of the table the comment is printed for every registered user. i.e. instead of just saying… Hello by James on 11/04/2012 it will say Hello by James on 11/04/2012 Hello by Tom on 11/04/2012 Hello by Emma on 11/04/2012 etc.

Like I said, the MySql table only shows one comment and it shows the correct user_id number of the user who uploaded the comment (which corresponds to the id in the users table). It must be the way I am echoing the comments but I’m new to PHP and MySql and I’m not sure I’m joining the tables correctly.

I’d be grateful for any help.

require_once("db_connect.php");
    if($db_server) {
        //If a connection to the database is made...
        mysql_select_db($db_database) or die ("<p>Couldn't find database</p>");

            //Print out existing comments
            $result = mysql_query("SELECT * FROM comments JOIN users ON comments.profile_id = $problemID");
            if (!$result) die ("Database access failed: " . mysql_error());
            $rows = mysql_num_rows($result);
            for ($j=0; $j<$rows; ++$j) {
                $str_comments .= "<span class='comment'>" . mysql_result($result, $j, 'comment') . "</span>";
                $str_comments .= " bt " . mysql_result($result, $j, 'username');
                $str_comments .= " on " . mysql_result($result, $j, 'comm_date') . "</br><br/>";
            }

            //Get any submitted comments and insert into database
            $comment = clean_string($_POST['comment']);
            if ($comment != '') {
                //If the submitted comment is not empty...
                if (strlen($comment)<200) {
                    mysql_query("INSERT INTO comments (`user_id`, `profile_id`, `comment`) 
                                VALUES ('{$_SESSION['user_id']}', $problemID, ('$comment'))") or die(mysql_error());
                }else{
                    $message = "Comment not submitted. The comment must be less than 200 characters long";
                }
            }
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:09:29+00:00Added an answer on June 1, 2026 at 8:09 pm

    In your query I don’t see a WHERE clause. Should be something like this:

    $result = mysql_query("SELECT * FROM comments JOIN users ON comments.profile_id = $problemID WHERE users.id=$userid");
    

    A join only joins to tables together, but it doesn’t “filter out” results, for that you still need the WHERE clause

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write documentation comments however I have a problem. /// <summary>
I have a page which list comments of users. My problem is that I
I have been looking for a proper comment system for my blogging site. I
I have a system of comments. Each comment may receive replies, and each reply
I have a problem consistently displaying Facebook Comments on my AJAX driven website. Each
I have problem with fancybox. I want to write a function that will run
I have this really weird bug at my page. I wrote this comment system
Problem I'm fairly new to design patterns, and have been studying the book, Head
I have a problem that I know is something local, related to transaction scope,
I´m trying to fix some problems adding a column to comments table and performing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.