Eiolon Posted December 28, 2012 Share Posted December 28, 2012 (edited) I am going to guess this is a problem with javascript, because I can use a typical submit button and have it work. I am trying to make it so a text link acts as the submit button and have it delete records that are selected via checkbox. When I click the delete items button it just refreshes the page and removes the check from the box. The record is still there. If I use a submit button it works. I have for the link: <a href="#" onclick="document.forms['delete_items'].submit();" title="Delete Items">Delete Items</a> I have for my form: <form id="delete_items" name="delete_items" method="POST" action=""> <table class="data"> <tr style="background:#F1F1F1;"> <td style="width:20px"></td> <td>Item</td> <td>Owner</td> <td style="width:80px">Received</td> <td style="width:80px">Returned</td> <td style="width:80px">Method</td> </tr> <?php while ($row_returns = $sth_returns->fetch(PDO::FETCH_ASSOC)) { ?> <tr onmouseover="this.bgColor='#EBFAFF';" onmouseout="this.bgColor='#FFFFFF';"> <td><input type="checkbox" name="<?php echo $row_returns['id'] ?>" value="<?php echo $row_returns['id'] ?>" style="border:none;" /></td> <td><?php echo htmlspecialchars($row_returns['item'], ENT_QUOTES, 'UTF-8'); ?></td> <td><?php echo htmlspecialchars($row_returns['owner'], ENT_QUOTES, 'UTF-8'); ?></td> <td><?php echo htmlspecialchars($row_returns['date_received'], ENT_QUOTES, 'UTF-8'); ?></td> <td><?php echo htmlspecialchars($row_returns['date_returned'], ENT_QUOTES, 'UTF-8'); ?></td> <td><?php echo htmlspecialchars($row_returns['method'], ENT_QUOTES, 'UTF-8'); ?></td> </tr> <?php } ?> </table> </form> I have for my PHP script: if ($_POST['id'] ) { foreach($_POST as $id) { $sth_delete_item = $dbh_mysql->prepare(' DELETE FROM returns WHERE id = :id '); $sth_delete_item->bindParam(':id', $id); $sth_delete_item->execute(); header("Location: index.php"); } } Edited December 28, 2012 by Eiolon Quote Link to comment Share on other sites More sharing options...
nogray Posted December 28, 2012 Share Posted December 28, 2012 From what I can see, you are trying to delete $_POST[id] but none of your checkboxes is named "id". If you view the source code (in your browser), you'll probably see the name as a number. Also, some servers don't pass arrays from your HTML form and you'll only get a string value "Array", you might want to check that as well. Quote Link to comment Share on other sites More sharing options...
Eiolon Posted December 28, 2012 Author Share Posted December 28, 2012 Thanks, problem solved! Quote Link to comment Share on other sites More sharing options...
Adam Posted December 30, 2012 Share Posted December 30, 2012 Have you considered styling a submit button as a link by the way, to avoid the JS dependency? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.