PHP MySQL Delete Data

Delete data from mysql using php

We already know how to establish connection between PHP web application and MySQL database system in our previous PHP tutorial. we also learnt to  select data from mysql and insert data into mysql database.

Now, In this PHP tutorial we will learn how to delete data from MySQL database using PHP script.

DELETE Statement

The UPDATE Statement is used to delete the records from an existing table.

DELETE  Statement Syntax

DELETE FROM table_name WHERE Condition

table_name – is the name of table which data to be deleted.

learn more about mysql DELETE statement : DELETE Statement

PHP Example of Delete data from MySQL database


$username = "username";
$password = "password";
$hostname = "localhost"; 

//connection to the mysql database,
$dbhandle = mysqli_connect($hostname, $username, $password,$database);

if(mysqli_query($dbhandle, "Delete from StudentMst where ID=4"))
echo "Record Deleted Successfully";
echo "Error!!";

//close the connection



Leave a Reply

Your email address will not be published. Required fields are marked *