mysqli checkbox multi delete

maoq3i

New Member
I've searched for similar issues but cannot seem to get this code to work correctly. Ideally the user ticks a checbox and clicks the "remove" button to remove that specific record. Right now I get redirected to self, minus my sidebar, and no errors or deletion.\[code\] <?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 queryif($r){ ?> <?php // 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>'; // 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">' . '<input type="checkbox" name="DEL" value="http://stackoverflow.com/questions/10545285/No" />'.' </td>'. '<td>' . '<input type="submit" name="delete" value="http://stackoverflow.com/questions/10545285/Remove" />' . '</td>' . '</tr>'; } echo '</table>'; // Close the table ?></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(isset($_POST['delete']))\[/code\]{\[code\]require_once ('../mysqli_connect.php'); //Connect to the dbforeach ($_POST['checkbox'] as $id => $value) $delquery = " DELETE FROM upload WHERE upload_id = {$id} AND owner_id =". $_SESSION['user_id']; //only lets deletion occur if user has a valid active session F OFF SPIDERS $done = mysqli_query ($dbc, $delquery); // Run the query if($done) { // Make sure the result is valid if (mysqli_num_rows($done)==1) { echo 'Record Deleted'; } else { echo 'error - delete failed'; } // Free the mysqli resources mysqli_free_result($result); } else { echo "Error! Query failed:" .$mysqli_error($dbc); } mysqli_free_result($done); mysqli_close($dbc);// END DELETE CODE BLOCK*****************************************************\[/code\]}?>
 
Back
Top