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

  • Home
  • SEARCH
  • 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 7785753
In Process

The Archive Base Latest Questions

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

When I post comments using the form field from the loop, the specific ID

  • 0

When I post comments using the form field from the loop, the specific ID of the blog is not carried over to the php script. So the comment is not assigned to the blog where it is meant to go.

<?php
$conn = mysql_connect("localhost", "ooze", "");
mysql_select_db ("ooze");
$result = mysql_query ("select * from blog") or die(mysql_error());
$result2 = mysql_query ("select * from blog, blogcomment where blog.ID = blogcomment.blogID") or die(mysql_error());
$i = 1;  
while($row = mysql_fetch_array($result))
{
echo "<h1>$row[title]</h1>";
echo "<p class ='second'>$row[blog_content]</p> "; 
echo "<p class='meta'>Posted by .... &nbsp;&bull;&nbsp; $row[date] &nbsp;&bull;&nbsp; <a href='#' onclick=\"toggle_visibility('something$i'); return false\">Comments</a><div id='something$i' style='display: none;'>";    
$i++;
while($row = mysql_fetch_array($result2))
{
echo "<p class='third' >$row[commentdate] &nbsp;&bull;&nbsp; $row[username]</p><p>said:</p> <p>$row[comment]</p>";
}
if ( isset ($_SESSION["gatekeeper"])) {
echo '<form method="post" name="result_'.$row["ID"].'" action="postcomment.php"><input name="ID" type = "hidden" value = "'.$row["ID"].'" /><input name="comment" id="comment" type="text" style="margin-left:20px;"/><input type="submit" value="Add comment" /></form>';
} 
else { 
echo '<p class="third"><a href="register.html">Signup </a>to post a comment</p>';
}
echo "</div>";
}
mysql_close($conn);
?>
  • 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:18:23+00:00Added an answer on June 1, 2026 at 8:18 pm

    dont use the same variable ($row) for both loops…

    change your second loop to look as:

     while($row2 = mysql_fetch_array($result2)){...}
    

    and change all the values from the second result to $row2["COLUMN_NAME"]

    also – don’t forget to surround the array index with quotation marks… it works but creates a notice, and makes the server work a little bit harder

    i.e: $row[username] should be $row["username"]

    this is a try to make a little bit order in your code:

    <?php
    $conn = mysql_connect("localhost", "ooze", "");
    mysql_select_db ("ooze");
    $result = mysql_query ("select * from blog") or die(mysql_error());
    $result2 = mysql_query ("select * from blog, blogcomment where blog.ID = blogcomment.blogID") or die(mysql_error());
    $i = 1;  
    while($row = mysql_fetch_array($result)){
        echo <<<str
        <h1>{$row["title"]}</h1>
        <p class ='second'>{$row["blog_content"]}</p> 
        <p class='meta'>Posted by .... &nbsp;&bull;&nbsp; {$row["date"]} &nbsp;&bull;&nbsp; <a href='#' onclick=\"toggle_visibility('something{$i}'); return false\">Comments</a><div id='something{$i}' style='display: none;'>
    str;
    
        $i++;
        while($comment = mysql_fetch_array($result2)){
             echo "<p class='third' >{$comment["commentdate"]} &nbsp;&bull;&nbsp; {$comment["username"]}</p><p>said:</p> <p>{$comment["comment"]}</p>";
        }
        if ( isset ($_SESSION["gatekeeper"])) {
            echo '<form method="post" name="result_'.$row["ID"].'" action="postcomment.php"><input name="ID" type = "hidden" value = "'.$row["ID"].'" /><input name="comment" id="comment" type="text" style="margin-left:20px;"/><input type="submit" value="Add comment" /></form>';
        } 
        else { 
            echo '<p class="third"><a href="register.html">Signup </a>to post a comment</p>';
        }
        echo "</div>";
    }
    mysql_close($conn);
    

    after all if i understood right what you were trying to achieve – than your script is not good, the second query should be inside the first loop and contain a WHERE blogID={$row["ID"]} in the end

    if you prefer getting all the comments in one query – it is good, but you need to arrange them and then show only the relevant for each “blog”, when you fetch them in a nested loop – the second query will only give you rows ones (because in the second time – it will already be empty)

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

Sidebar

Related Questions

I have a blog post page with comments. Any user (logged in or not)
The django contrib comments form i'm using: {% get_comment_form for post as form %}
I'm using a simple form with a name, email and comment field to send
I have three models: Post , Comment , User and Vote . I'm using
I'm implementing a Blog with Post and votable Comments. When loading a Post, I
I'm trying to add comments to a Post model class Comment < ActiveRecord::Base belongs_to
I am trying to pass dynamically created form fields to a php script, and
Here is a simple scenario: I have a blog post with comments attach to
I am creating a JavaScript / ajax comment form using the jQuery Validation Plugin.
I am working on a comment script using ajax, json and jquery. I have

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.