Home  >  Article  >  Database  >  How to Pass a Variable in a Delete Link for PHP Forms?

How to Pass a Variable in a Delete Link for PHP Forms?

Susan Sarandon
Susan SarandonOriginal
2024-10-28 07:41:01168browse

How to Pass a Variable in a Delete Link for PHP Forms?

How to add a delete button to a PHP form that will delete a row from a MySQL table

It is essential to pass a variable in the delete link. You can either pass the variable (?php echo $contact['name']; ?) in a hidden field or pass it in the URL.

Step 1
Replace the original code:

        <td class=&quot;contact-delete&quot;>
                <form action='delete.php' method=&quot;post&quot;>
                        <input type=&quot;hidden&quot; name=&quot;name&quot; value=&quot;&quot;>
                        <input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Delete&quot;>
                </form>
        </td>

Step 2
With the following code:

        <td class=&quot;contact-delete&quot;>
                <form action='delete.php?name=&quot;<?php echo $contact['name']; ?>&quot;' method=&quot;post&quot;>
                        <input type=&quot;hidden&quot; name=&quot;name&quot; value=&quot;<?php echo $contact['name']; ?>&quot;>
                        <input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Delete&quot;>
                </form>
        </td>

The above is the detailed content of How to Pass a Variable in a Delete Link for PHP Forms?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn