Deleting data from table in php mysql

Deleting mysql tables data with php script.

In this tutorial of php we are going to delete data from table , for deleting data from an existing table of mysql data we need to use following sql query.


For deleting selected data from mysql table we use following query : DELETE FROM <table_name> where <field=’value’>

In my case i have a database named as mydatabase and there is a table in that database named as students_data , so form that table i want delete some data.


//creating connection.
$mycon = mysqli_connect('localhost','root','','mydatabase');
//testing connection.
if($mycon == true)
echo "Successfully connected.";
die('Problem with connection'.mysqli_connect_error());
//delete query.
$query = "DELETE FROM students_data where name='Gaurav'";
$res = mysqli_query($mycon,$query);
//testing query.
if($res == true)
echo "Query successfully executed. data deleted";
die("Problem in execution".mysqli_connect_error());



Successfully connected.Query successfully executed. data deleted