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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:36:19+00:00 2026-06-08T20:36:19+00:00

I’m trying to get multiple deletion capability, and this is what I have so

  • 0

I’m trying to get multiple deletion capability, and this is what I have so far:

<?php
  echo '<h3>Welcome to your profile, '. $_SESSION['first_name'] . '</h3>';

  require_once ('../mysqli_connect.php'); //Connect to the db

  // Make the query

  $q = "SELECT upload_id, title, genre, length, created, views
        FROM upload
        WHERE owner_id =". $_SESSION['user_id'] ."
        ORDER BY title ASC";


  $r = mysqli_query ($dbc, $q); // Run the query

  if($r) {
    ?>
    <table align="center" cellspacing="3" cellpadding="3" width="75%">
      <tr>
        <td align="left"><b>Title</b></td>
        <td align="left"><b>Genre</b></td>
        <td align="left"><b>Pages</b></td>
        <td align="left"><b>Submitted</b></td>
        <td align="left"><b>Views</b></td>';
          <form action="/nbproject/newwriter_profile.php" method="post">
          <?php
            while ($row = mysqli_fetch_array($r,MYSQLI_ASSOC)) {
              echo '<tr><td align="left">' 
                . $row['title'] . '</td><td align="left">'
                . $row['genre'] . '</td><td align="left">'
                . $row['length'] . '</td><td align="left">'
                . $row['created'] . '</td><td align="left">'
                . $row['views'] . '</td><td align="left">'
                . '<input type="checkbox" name="checkbox[]"'
                . 'id="checkbox[]"  value='.$row['$upload_id'] //this upload id is auto-increment (see first note)
                .' />'.' </td>'. '</tr>';
            }
          ?>
    </table>
    <input type="submit" name="delete" value="Delete" align="right"/>
  </form>
  <?php
    mysqli_free_result ($r); // Free up the resources
  } else { // If it did not run okay
    // Public Message:
    echo '<p class="error">Your submissions could not be retrieved.  We apologize for any inconvenience.</p>';
    // Debugging message:
    echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>';
  } // End of if ($r) IF.

  mysqli_close($dbc); // Close the database connection

  if($_POST['delete']) {
    require_once ('../mysqli_connect.php'); //Connect to the db

    $checkbox = $_POST['checkbox']; //from name="checkbox[]"
    $countCheck = count($_POST['checkbox']);

    for($i=0;$i<$countCheck;$i++) {
      $del_id  = $checkbox[$i];
      //----------------------------------
      $sql = "DELETE from `upload` where `upload_id` = $del_id AND `owner_id` = {$_SESSION['user_id']}";
      $result = $mysqli->query($sql) or die(mysqli_error($mysqli)); //added session information after hearing about google spider armageddon scenarios
    }

    if($result) {
      header('Location: newwriter_profile.php');
    } else {
      echo "Error: ".mysqli_error();
    }
  }
?>

1st Note: Basically the registered user is greeted by their profile page which shows them their uploads and some upload info. I’d like a checkbox alongside each upload and a delete button wherever else on the page. So I tried this.

Right now it will redirect with no errors and nothing is deleted. Also, hitting Delete without a checkbox selected returns an error. Thanks for the help in advance, solving this issue will also solve another I am having and will be a huge relief.

I can’t think of a way to get the upload id to be linked to the checkbox. My brain hurts.

EDIT: This is the current output of the viewsource for the checkbox, using dcoder’s recommendation and the vardump test. input type=”checkbox” name=”checkbox[]” id=”checkbox[]” value= “” />

vardump test output: array(3) { [0]=> string(0) “” [1]=> string(0) “” [2]=> string(0) “” }

EDIT: delete functions are currently as follows:

    function submit_delete() {
    if($_POST['delete'] && $_POST['checkbox[]']) { //Check to see if a delete command         has been submitted.
//This will dump your checkbox array to your screen if the submit works.
//You can manually check to see if you're getting the correct array with values
//var_dump($_POST['checkbox']);//Comment this out once it's working.
deleteUploads($_POST['checkbox[]']);
    }
   }


   function deleteUploads ($id_array) {
   if (count($id_array) <= 0) { return; }//bail if its empty
   $delete_success = false;
   foreach ($id_array as &$id) {
   $sql = "DELETE from `upload` where `upload_id`=$id AND `owner_id`=   {$_SESSION['user_id']}";
   $result = $mysqli->query($sql) or die(mysqli_error($mysqli));
   if ($result) { $delete_success = true; }
   }

    if($delete_success) {
   header('Location: newwriter_profile.php');
  } else {
  echo "Error: ".mysqli_error();
  }
  }


//Test deleteUploads (remove once you know the function is working)
//$test_ids = array();
//$test_ids[] = 5;//make sure this id is in the db
//$test_ids[] = 7;//this one too
submit_delete();
deleteUploads($id_array);//should remove ids 10 and 9//

mysqli_close($dbc);

EDIT: Currently is as follows:

        while ($row = mysqli_fetch_array($r,MYSQLI_ASSOC))
    {
        echo '<tr><td align="left">' .
        $row['title'] . '</td><td align="left">'
        . $row['genre'] . '</td><td align="left">'
        . $row['length'] . '</td><td align="left">'
        . $row['created'] . '</td><td align="left">'
        . $row['views'] . '</td><td align="left">' //. var_dump($row) //dump row value              for testing
        . '<input type="checkbox" name="checkbox[]"'. 'id="checkbox[]"  value=               "'.$row['upload_id'].'"'.' />'.' </td>'. '</tr>';

commented out vardump, shows that each checkbox is getting the correct upload_id…

    function submit_delete() {
   if(!is_null($_POST['delete']) && !is_null($_POST['checkbox[]'])) { //Check to see if              delete command has been submitted.
//This will dump your checkbox array to your screen if the submit works.
//You can manually check to see if you're getting the correct array with values
//var_dump($_POST['checkbox']);//Comment this out once it's working.
deleteUploads($_POST['checkbox[]']);

   }
   else {
   echo "Error: submit_delete called without valid checkbox delete.";
    }
   }


   function deleteUploads ($id_array) {
    if (count($id_array) <= 0) {   echo "Error: No deletes in id_array!";    var_dump($id_array); return; }//bail if its empty
   $delete_success = false;
   foreach ($id_array as &$id) {
   $sql = "DELETE FROM `upload` WHERE `upload_id`=$id AND `owner_id`=   {$_SESSION['user_id']}";
    $result = $mysqli->query($sql) or die(mysqli_error($mysqli));
   if ($result) { $delete_success = true; }
  }

  if($delete_success) {
 header('Location: newwriter_profile.php');
  } else {
  echo "Error: ".mysqli_error();
 }
}


//Test deleteUploads (remove once you know the function is working)
//$test_ids = array();
//$test_ids[] = 5;//make sure this id is in the db
//$test_ids[] = 7;//this one too
submit_delete();
//deleteUploads($id_array);//should remove ids 10 and 9//

mysqli_close($dbc);

on page load, I get the error “submit_delete called…”
after I tick some boxes and hit delete… I get the same error. Bailing out on the $_POST[‘checkbox[]’] and getting a NULL value.

  • 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-08T20:36:21+00:00Added an answer on June 8, 2026 at 8:36 pm

    I solved the problem. I ran a grant * permission statement in MySQL after exhausting every other option. Apparently I had created the database user prior to creating the Uploads table. Thanks all for the help

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
Basically, what I'm trying to create is a page of div tags, each has

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.