PHP Delete Data From MySQL
DELETE FROM table_name
WHERE some_column = some_value
look at the "Student" table:
ID name lastname admsn_date
1 Ankit Bhardwaj 6/9/2016
2 Ashish Rajput 5/9/2016
3 Rahul Paswan 4/9/2016
The following examples delete the record with id=2 in the "Student" table:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "data";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// sql to delete a record
$sql = "DELETE FROM Student WHERE id=2";
if ($conn->query($sql) === TRUE) {
echo "Record deleted successfully";
} else {
echo "Record Can't Delete: " . $conn->error;
}
$conn->close();
?>
After the record is deleted, the table will look like this:
ID name lastname admsn_date
1 Ankit Bhardwaj 6/9/2016
2 Rahul Paswan 4/9/2016
No comments