1

I have created a cart page from a table named booking .
The cart page has item name and asubmit button named "delete".
There has a lot of items in the cart sheet and every item has a "delete" submit type button.
The items are inside one form.

I need to delete one item from the table booking by clicking the "delete" button of the item.
How can I do it using PHP.

    <form action="delete.php" method="POST">
       <div>
           <h2>Item1</h2>
           <input type="submit" name="item1" value="delete">
       </div>
       <div>
           <h2>Item2</h2>
           <input type="submit" name="item2" value="delete">
       </div>
       <div>
           <h2>Item3</h2>
           <input type="submit" name="item3" value="delete">
       </div>
       ...
       <!--There has a lot of items like that-->
    </form>

Now for example I need to delete item100. How can I do it?


Edit: Here is the delete.php code-

<?php      
$query = mysql_query("delete from notification where item = 'item100'") or die(mysql_error());
?>
1
  • you should also show us your PHP code Commented Dec 12, 2015 at 13:37

2 Answers 2

3

You do not need form and submit input. You could use links:

<a href="delete.php?id=100">delete</a>

This is a GET so you need to perform a redirect to your incoming page to avoid back button problems or use Ajax or both.

If you want to use your form and submit button you could add some Javascript to set an hidden input or use a <button />

Sign up to request clarification or add additional context in comments.

1 Comment

NEVER delete data with just a link. Sure, it will work, but you might also have a web crawler delete every record in your database!
0

Although there is sql injection risks you will need to deal with, this is how you would do it using your current method. Keep in mind you will still need to modify your code to prevent sql injections.

    <?php $query = mysql_query("delete from notification where item = '".$_POST['name']."'") or die(mysql_error()); ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.