PHP MySQL delete Query Syntax from the Table with MySQLi Example

PHP Delete Data in MySQL

To delete the value of previously saved recode, we have to use the delete query.

In other word, the delete query is used to deleting the existing records.

Note:Here you also specify the where clause and where clause is used to define which records should have to delete. If you can not use where clause then all the records will be deleted by default.

Example – 1 Delete Data in MySQL Example

$server = "localhost";
$user = "root";
$password = "";
$dbname = "elex_tutorial";

// Create connection
$connection = new mysqli($server, $user, $password, $dbname);
// Check connection
if ($connection->connect_error) {
    die("Connection failed: " . $connection->connect_error);

// sql to delete a record
$sql = "DELETE FROM `User` WHERE `id`=1";

if ($connection->query($sql) === TRUE) {
    echo "Record deleted `";
} else {
    echo "Error deleting record: " . $connection->error;


In the above code, we delete the record to the “User” table of “elex_tutorial” database. If the code run . then the output show a Record deleted successfully. So you have to check in the user table also.

You can leave a response, or trackback from your own site.
Leave a Reply to the article

Learn PHP

Learning & Certifications
Follow Us
Facebook Icon   Linked In Icon   Twitter Icon  
Validation and Recognition

Valid CSS! Valid HTML5!          Protected by Copyscape