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
`
<?php $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; } $connection->close(); ?>
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.