Delete data from database in PHP

Initially we need to add delete button in our form by adding HTML code in form as follows:

    <input type="submit" name="submit" value="detele">

Lets learn how to delete record from  database using delete button in html form. In this section we are going use DELETE query to delete data from mysql database. 

Syntax for deleting data from database:

    "DELETE FROM table_name" 

above query is used to delete table from database. Incase you want to delete particular record or row from database, we need to use WHERE clause usually primary key column.

Syntax :

    "DELETE FROM table_name WHERE Column_name(primary key)" 

Below we have code for deleting record from database. delete.php file code as follow:

<?php
$conn=new mysqli('localhost','root','','vibha');

if(isset($_GET['del']))
{
    $id=$_GET['del'];
    $query="DELETE FROM registration WHERE id='$id'";
    $result=mysqli_query($conn,$query);
   
    echo "data deleted";
   
}
?>





Comments

Popular posts from this blog

Python