How to delete a record in SQL using PHP

Example – Delete from table users $row[‘id’]

<a href="?id=<?php echo $row['id']; ?>">Delete</a>

<?php
$connect = mysqli_connect($servername, $username, $password, $dbname);
if(isset($_GET['id']) == $row['id']) {
    $del = 'DELETE FROM users WHERE id ='.$row['id'];
    mysqli_query($connect, $del);
    mysqli_close($connect);
    header('Location: index.php');
    exit;
}
?>

Leave a Reply