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 9253507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:14:13+00:00 2026-06-18T11:14:13+00:00

I have been creting a php website that allows users to add comments to

  • 0

I have been creting a php website that allows users to add comments to an image that is within the system.

The way my code currently works is that it gets all of the comments for that image and places them into a table using a while loop:

$commResult = mysql_query("SELECT u.userID, u.USERNAME, c.COMMENT, c.DATE_ADDED, c.ACTIVE, c.id FROM USERS u, COMMENTS c WHERE u.id = c.user_id and c.box_id = $boxId ORDER BY c.DATE_ADDED DESC");

while ($row = mysql_fetch_array($commResult))
    {
        if ($row[4] != 0)
        {
            echo "<tr><td><a href='User.php?uid=$row[0]'>$row[1]</a></td>";
            echo "<td style='text-align:right;'>" . date("d M y g:iA", strtotime($row[3])) ;
            if (isLoggedIn())
                echo " - DELETE";
            echo "</td></tr>";
            echo "<tr><td colspan='2'>" . $row[2] . "</td></tr>";
        }
    }

The problem i am having is that i would like to put a submit button where the word DELETE is. This would create a button for each comment row and therefore if clicked the code would not know what button has been pressed. Is there anyway to get arround this so each button has a individual ID so when the code is submitted it knows what the id of the comment is and therefore i am able to process a delete on the database table for that comment ID.

I have tried adding this piece of code where the word DELETE is:

if (isLoggedIn())
                echo " - <button type='submit' name='delCom_sub' value='$row[5]' >X</button>";

However when i try to handle the button click using the following code:

if (!empty($_POST['delCom_sub']))
{
    echo "test";
}

IF i click a button the word “test” is never displayed.

  • 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-18T11:14:14+00:00Added an answer on June 18, 2026 at 11:14 am

    It can be done with a separate form for each comment row. The ID of the comment is stored in a hidden field. Using this method you need to remove any parent form to prevent nested forms.

            if (isLoggedIn())
            {
                echo '<form action="delete.php" method="post">
                      <input type="hidden" name="id" value="' . (int)$row['id'] . '" />
                      <input type="submit" value="Delete" />
                      </form>';
            }
    

    On the page that you post to, ie delete.php:

    if(isset($_POST['id']) && isLoggedIn())
    {
        // do the delete with $_POST['id']
    }
    

    Other than that, you could do it with Javascript by populating a hidden field when a button is clicked. Another option would be to store the comment ID in a submit button’s name attribute, doing that you would have to loop over the post variables and parse out the ID.

    Example using the button name:

    if (isLoggedIn())
                echo " - <input type='submit' name='delete_" . (int)$row['id'] . "' value='Delete' />";
    

    On the receiving page:

    if($_SERVER['REQUEST_METHOD'] == 'POST' && isLoggedIn())
    {
        foreach($_POST as $key => $value)
        {
            if(strpos($key, 'delete_') === 0)
            {
                $id = substr($key, 7);
                // do the delete for $id
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been creating a website to allow users to rate an image uploaded
I have been creating a website where my users can rate images that have
So i have been creating this framework thing that basically puts together source code
I have been reading that creating dependencies by using static classes/singletons in code, is
I have been creating a php application that makes quite a few queries to
I have been creating a peer to peer connection for a new game, that
I have been creating an image gallery with jQuery, all is done. The images
I have a website which I have been working on creating very rapidly, and
I am developing a project that lately have been taking off with increased popularity.
Possible Duplicate: Simple PHP Mailer Script i run a small website and we 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.