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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:11:56+00:00 2026-06-11T12:11:56+00:00

I have a jquery delete statement and it’s only deleting the NEWEST upload on

  • 0

I have a jquery delete statement and it’s only deleting the NEWEST upload on my files (using mysql) Say I had “file uploaded first”, “file uploaded second”, “file uploaded last(newest file)”. If I click “file uploaded first or second”, it deletes the newest (file uploaded third).

    $(document).on('click', '.del', function(){
    var sid = $(this).next('.hiddenVid').val();
    $.ajax({
        type: "GET",
        url: "delete.php",
        data: {id:sid}
    });
    return false;
});
  • 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-11T12:11:57+00:00Added an answer on June 11, 2026 at 12:11 pm

    this is your error ->

    var sid = "$vid";. 
    

    It will only produce the ID for the latest item that you put in.

    Add an item to your echo statement so you can reference it later in the click function.

    Add a reference to the vid in a hidden input.

    Change this

    $option = "<td><form method='POST'><button type='submit' name='del' class='del'><i class='icon-remove'></i></button></form></td>";
    

    To this:

    $option = "<td><form method='POST'><button type='submit' name='del' class='del'><i class='icon-remove'></i></button><input type='hidden' class='hiddenVid' value='".$vid."'/></td>";
    

    Change your click function to reference the real sid now.

    $(function(){
        $(".del").click(function(){
            var row = $(this).parent();
            var sid = $(this).next('.hiddenVid').val();
            alert(sid);
            $.ajax({
                type: "GET",
                url: "delete.php",
                data: {id:sid}
            });
            return false;
        });
     });
    

    If you want to return the rows after the update, you’ll need to spit the data back to be printed, based on the above method you use to retrieve the rows and return them, you could reuse it.

    $id = mysql_real_escape_string($_REQUEST['id']);
    $DB->Query("DELETE FROM `files` WHERE `id`='$id'");
    
    if(TRUE == (unlink("uploads/$id")):
        $DB->Query("SELECT * FROM `files` WHERE `author`='$username'");
        $file = $DB->Get();
        $obj = new stdClass();
        $i = 0;
        foreach($file as $key => $value){
            $n = $value['name'];
            $vid = $value['id'];
            $date = "<td>".$value['date']."</td>";
            $fname = "<td><a id='$vid' href='download.php?id=$vid'>$n</a></td>";
            $option = "<td><form method='POST'><button type='submit' name='del' class='del'><i class='icon-remove'></i></button></form></td>";
            $size = "<td>".filesize("uploads/".$vid."/".$value['name'])." bytes</td>";
            $obj->$i = $files = "<tr>".$fname.$size.$date.$option."</tr>";
            $i++;
        }
        echo json_encode($obj);
    endif;
    

    Now we need to change the click handler to expect a dataType and replace the existing data in the table.

    $(function(){
        $(".del").click(function(){
            var row = $(this).parent();
            var sid = $(this).next('.hiddenVid').val();
            alert(sid);
            $.ajax({
                type: "GET",
                url: "delete.php",
                dataType: 'json',
                data: {id:sid},
                success: function(data){
                  $('table').empty();
                  $.each(data, function(i,obj){
                      $('table').append(obj);
                  }
                }
            });
            return false;
        });
     });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery function to delete a file from a list and then
I have a list view in jQuery Mobile with delete buttons in them. <ul
I have a delete button on a table and a jquery on click eventlistener
I have the following function in my jQuery code: function checkUNSelectBox(item){ $('#DELETE option').each(function(){ <!--alert(item);-->
I have JQuery UI Dialog opening on pressing CTRL + Q using the following
I have jQuery on my site. I also have a youtube video using a
I have a jquery scorlling table which is populated dynamically. I am using Bob
I am using ASP.NET MVC C# I have a jQuery call that deletes a
I have a php page where I add and delete items from database using
I have two jQuery files that were conflicting with each other. I was getting

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.