Jump to content

Recommended Posts

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 by Eiolon
Link to comment
https://forums.phpfreaks.com/topic/272455-text-link-as-submit-button/
Share on other sites

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.