How can PHP be used to delete specific entries in a database table based on user input?
To delete specific entries in a database table based on user input, you can use PHP to capture the input data, sanitize it to prevent SQL injection, and then execute a DELETE query with the specified criteria.
<?php
// Assuming connection to database is already established
if(isset($_POST['delete_entry'])) {
$entry_id = $_POST['entry_id']; // Assuming entry_id is the identifier for the entry to be deleted
// Sanitize the input
$entry_id = mysqli_real_escape_string($connection, $entry_id);
// Execute the DELETE query
$query = "DELETE FROM table_name WHERE entry_id = '$entry_id'";
$result = mysqli_query($connection, $query);
if($result) {
echo "Entry deleted successfully.";
} else {
echo "Error deleting entry: " . mysqli_error($connection);
}
}
?>
Keywords
Related Questions
- Are there specific scenarios where JSON could serve as an alternative to traditional databases in PHP applications?
- What are some common methods for parsing and extracting specific data from a text file in PHP?
- How can PHP be used to automatically update an "Ewige Torschützenliste" based on current season stats?