PHP delete
Wed Nov 15 2023 15:49:36 GMT+0000 (Coordinated Universal Time)
Saved by
@prasit12
<?php
// Replace with your database credentials
$servername = "your_servername";
$username = "your_username";
$password = "your_password";
$dbname = "your_database";
// Create connection using MySQLi
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Check if ID is provided in the URL
if (!isset($_GET['id'])) {
echo "No ID provided";
exit();
}
$id = $_GET['id'];
// Delete the record based on the provided ID
$sql_delete = "DELETE FROM users WHERE id = $id";
if ($conn->query($sql_delete) === TRUE) {
// Deleted successfully, you can redirect or show a message
header("Location: your_page.php"); // Redirect to your page
exit();
} else {
echo "Error deleting record: " . $conn->error;
}
// Close connection
$conn->close();
?>
content_copyCOPY
https://chat.openai.com/
Comments