DELETE RECORDS IN PHP/MYSQL


Delete Records in mysql


Delete records from database is a easy task the main logic behind deleting a record from database table is delete command of my sql as follows

Delete from tableName where id = something



The data you want to delete will be pass in id and the record will be deleted from database make sure if you delete a record from database you can't recover that record .


You need following things for deleting record


First you have to connect your script with database than make sure you are passing the id for that record you wish to delete .

Php code to delete the record from database.


<?php
require_once('connection.php');
$id = $_GET['id'];
$query = "DELETE FROM `crud` WHERE id=$id"; //query for delete record
$result = mysqli_query($connection, $query);
if($result){
header('location: display.php');
}else{
echo "Can't delete at this moment please try again";
header( "refresh:5;url=display.php" );
}
?>

If have any query related to this code kindly comment in comment-box.