How can the selected entry from a pulldown menu be used to delete a corresponding entry from a database in PHP?

To delete a corresponding entry from a database in PHP based on a selected entry from a pulldown menu, you can use a form with a pulldown menu that lists the entries from the database. When the form is submitted, you can retrieve the selected entry using $_POST, and then use this value to construct a DELETE query to remove the corresponding entry from the database.

<?php
// Connect to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Check if form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $selectedEntry = $_POST['selectedEntry'];

    // Construct DELETE query
    $sql = "DELETE FROM your_table WHERE entry = '$selectedEntry'";

    // Execute query
    if ($conn->query($sql) === TRUE) {
        echo "Entry deleted successfully";
    } else {
        echo "Error deleting entry: " . $conn->error;
    }
}

// Close connection
$conn->close();
?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <select name="selectedEntry">
        <option value="entry1">Entry 1</option>
        <option value="entry2">Entry 2</option>
        <option value="entry3">Entry 3</option>
    </select>
    <input type="submit" value="Delete Entry">
</form>