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

The Archive Base Latest Questions

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

I have this chunk of code, which is displayed on a user’s journal page.

  • 0

I have this chunk of code, which is displayed on a user’s journal page. They can add an entry and they have the option to delete an entry once it’s on the page.

Ill show the code with some comments and then explain the problem.

// Figures out how many recent posts to display
$posts = $config_journalposts + 1;
if($noposts!=1) {
    // Gets the data from the query
    while(($row = mysql_fetch_array($journalquery)) && ($posts > 1)) {
        // For each of the posts that were gathered, display the following:
        echo '<table border="0" width="100%">
            <tr>
                <td colspan="2" style="vertical-align:bottom;">
                    // Display the title as a link to be used as a permalink
                    <a href="?id='.$row['id'].'"><p class="fontheader">'.$row['title'].'</p></a>
                </td>
            </tr>
            <tr>
                // Show the o-so-important content
                <td width="100%" style="vertical-align:top;padding-left:10px;">
                    '.$row['content'].'
                </td>
            </tr>
            <tr>
                // Show the date
                <td style="font-size:8pt;padding-top:10px;">'.$row['date_day'].'/'.$row['date_month'].'/'.$row['date_year'].'</td>';
                    // Checks if the current user is the owner of the journal or an admin
                    if($_SESSION['user']==$pageowner || $_SESSION['user_rank']=='Admin') {
                        echo '<td align="right">

                            // FOCUS POINT
                            <form method="POST" id="deljournal">
                                <input type=\'hidden\' name=\'delete_id\' value=\''.$row['id'].'\' />
                                // A delete button that executes a bit of Javascript
                                <button type="button" class="button" name="delete" value="Delete" onClick="delete_journal()" />Delete</button>
                            </form>
                            // END FOCUS POINT

                        </td>';
                    }
                echo '</tr>
            </table>
        <hr>
        ';
    $posts --;
}

Here is the Javascript that gets triggered on the button press

function delete_journal() {
    var answer = confirm("Are you sure you want to delete this journal entry?")
    if (answer){
        // Submits the form
        $("#deljournal").submit()
    }
}

This javascript triggers the forum in the PHP code above which reloads the page and triggers this at the very top of the page, before the tag

if(($_POST['delete_id'])) {
    // Gets the post ID from the hidden forum tag
    $deleteid = addslashes(strip_tags($_POST['delete_id']));

    // Deletes the row that has the ID of the hidden form
    mysql_query("DELETE FROM `gamezoid_accounts`.`journal_$pageowner` WHERE `id`='$deleteid'");
}

Now, for the problem. In the while loop, this form gets repeated over and over. What happens is that upon pressing the delete button, it triggers the form that has the ID “deljournal”. Since all of them have the ID “deljournal” it does the one at the top of the page. Trying to embed the post ID into the form ID breaks the code because the mysql_query doesn’t know that the delete function has been triggered in the first place.

Any way around this?

Reason why I’m using Javascript as a trigger is for the confirmation popup in case anyone askes.

Anyways, thanks heaps for reading this far!

  • 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-13T09:18:07+00:00Added an answer on June 13, 2026 at 9:18 am

    Found a solution.

    I have changed the form to be

    <form method="POST" id="deljournal_'.$row['id'].'">
        <input type=\'hidden\' name=\'delete_id\' value=\''.$row['id'].'\' />
    </form>
    <button type="button" class="button" name="delete" value="Delete" onClick="delete_journal_'.$row['id'].'()" />Delete</button>
    

    by adding the journal entry ID into the ID of the form and the onClick function. The javascript is just below it outside the table cell and looks like:

    <script type="text/javascript">
        function delete_journal_'.$row['id'].'() {
            var answer = confirm("Are you sure you want to delete this journal entry?")
            if (answer){
                $("#deljournal_'.$row['id'].'").submit()
            }
        }
    </script>
    

    where the entry ID has been added to the function name and form ID tag. By putting the Javascript into a while loop and not into an external file, it can be manipulated with the loop to have the same values.

    It is a bit messy and will slightly increase load times + execution times but it was the quickest way that I could find.

    Hope this helps anyone else who has been having a similar problem.

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

Sidebar

Related Questions

I have this chunk of code which is placed in accelerometer: didAccelerate which changes
If I have a chunk of code like this: .hover( function () { hoverState($(#navbar
I have a small chunk of code I can't seem to get working. I
I have this chunk of code in an R script, and what it does
I have this code snippet: val chunks = blob.map(_.id).distinct.grouped(100).toSeq val output = (for (chunk
I have this code here, which get a plain text, and turns it to
I have this chunk of javascript that's kind of hacked around from http://www.developphp.com/view.php?tid=1248 and
I have this string containing a large chunk of html and am trying to
I have this form, in which i need to populate a combo box with
I have this function // add history paths and save data function AddPath( strTag,

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.