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

The Archive Base Latest Questions

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

I am currently populating an array with checkboxes, imploding the array variable and using

  • 0

I am currently populating an array with checkboxes, imploding the array variable and using that variable in an IN clause within a DELETE function. var_dump is showing that I am creating a correct query, yet I can’t get any deletion to occur. This is a new approach to an existing problem I have had for a month or so.

Here’s what I have.

//Connect to the db
$id_array = NULL;

// Make the query to display user's uploads
 $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)
    {
        // If it ran okay, display the records
        echo '<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>
           </tr>';

        // Fetch and print all the records:
?><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">' //. var_dump($row) //dump row value for testing
       . '<input type="checkbox" name="checkbox[]"  value= "'.$row['upload_id'].'"'.' />'.' </td>'. '</tr>';
    }
   echo '</table>'; // Close the table
        ?>

the above code creates a simple table, each record is shown with a corresponding checkbox, check to delete then click “Delete”

         <input type="submit" name="delete" value="Delete" align="right"/> 
       </form>

<?php
   } // End of if ($r) IF.
    mysqli_close($dbc); // Close the database connection

custom delete function:

function submit_delete() {
  if(!is_null($_POST['delete']) && !is_null($_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.
    $id_array = $_POST['checkbox'];
    $id_array = array_map('intval', $id_array);
    $id_array = array_unique($id_array);
    $id_array = implode(',',$id_array);
    //var_dump($id_array);
    deleteUploads($id_array);

  }
  else {
    echo "Error: submit_delete called without valid checkbox delete.";//var_dump($_POST['checkbox']);
  }
}

$delete_success = false;
function deleteUploads ($id_array) {
    require_once(my connection to db);

    mysqli_free_result($r);

  if (count($id_array) <= 0) {   echo "Error: No deletes in id_array!"; echo 'wtf'; }

  //var_dump($id_array);

above var dump shows correct id’s as shown in my mysql database

    $gone = "DELETE  FROM `upload` WHERE `upload_id` IN ("."$id_array".")";
    var_dump($gone);

above var verifies that the query is formed correctly, with comma separated id’s

    $goodbye = mysqli_query($dbc, $gone);

    if ($goodbye) { $delete_success = true; var_dump($delete_success);}
    else { $delete_success = false;}
    var_dump($delete_success);

above var dump shows bool false

    //mysqli_close($dbc);
    if($delete_success == true) { echo 'done';
    header('Location: newwriter_profile.php');
  } else
      {
    echo "Error b/c delete failed";

the above echo shows after checking any number of boxes and hitting delete

      }

  }


submit_delete();

mysqli_free_result($goodbye);
mysqli_close($dbc);


?> 
  • 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:34:52+00:00Added an answer on June 8, 2026 at 8:34 pm

    I solved my problem. I realized that during my haphazard development, I had created my database user with associated privileges BEFORE actually creating my uploads table. I ran a grant permission statement on my database user and miraculously I am able to delete using the above code. This also solved another issue I was having involving SESSION variables getting lost between pages.

    This was an absolute nightmare – I hope this helps someone else as well. Thanks for your input.

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

Sidebar

Related Questions

I am currently populating my WPF grid using a data collection that implements ITypedList
I am populating my Google chart using JSON currently, but I need to customize
Currently i am populating the table with the items using for each , below
Currently I'm populating an array in one line, e.g. self.monthMonths = [[NSArray alloc] initWithObjects:@January,
I am populating a secondary table with an observable array that is a child
I currently have objects populating the screen randomly and bouncing around the stage. The
Currently, I am writing a MiddleWare application that synchronizes information between and accounting application
Currently I am using HTML files for parts of my user interface. I display
currently, I`m implementing a map App with Mono4Droid and there I`m using a WebView
Currently working with converting SQLException error messages into messages that are more useful for

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.