⊗ppPmDPDR 391 of 447 menu

Deleting Data from the Database Using GET Requests

Let's now delete records from the database by passing the id for deletion via GET parameters.

Suppose we have a GET parameter named del. Let's get the id for deletion into a variable:

<?php $del = $_GET['del']; ?>

Let's form a deletion query:

<?php $query = "DELETE FROM users WHERE id=$del"; ?>

Delete the record from the database:

<?php mysqli_query($link, $query) or die(mysqli_error($link)); ?>

Make it so that in the address bar it is possible to send a GET request with the user's id and this user gets deleted from the database.

Modify the previous task so that the page has links to delete each user:

<a href="?del=1">user1</a> <a href="?del=2">user2</a> <a href="?del=3">user3</a>

The links, of course, should be generated in a loop from the data received from the database.

Modify the previous task so that you have the following HTML code:

<ul> <li>user1 <a href="?del=1">delete</a></li> <li>user2 <a href="?del=2">delete</a></li> <li>user3 <a href="?del=3">delete</a></li> </ul>

Modify the previous task so that you have the following HTML code:

<table> <tr> <th>id</th> <th>name</th> <th>age</th> <th>salary</th> <th>delete</th> </tr> <tr> <td>1</td> <td>user1</td> <td>23</td> <td>400</td> <td><a href="?del=1">delete</a></td> </tr> <tr> <td>2</td> <td>user2</td> <td>25</td> <td>500</td> <td><a href="?del=2">delete</a></td> </tr> <tr> <td>3</td> <td>user3</td> <td>23</td> <td>500</td> <td><a href="?del=3">delete</a></td> </tr> </table>
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline