How can PHP be used to differentiate between multiple buttons in a webshop to display the correct product information from a MySQL database?

To differentiate between multiple buttons in a webshop and display the correct product information from a MySQL database, you can pass a unique identifier (such as product ID) along with the button click event. In the PHP script handling the button click, you can retrieve this identifier and use it to fetch the corresponding product information from the database.

<?php
// Assuming the product ID is passed as a parameter named 'product_id'
if(isset($_GET['product_id'])) {
    $product_id = $_GET['product_id'];
    
    // Connect to MySQL database
    $conn = mysqli_connect("localhost", "username", "password", "dbname");
    
    // Retrieve product information based on the product ID
    $query = "SELECT * FROM products WHERE id = $product_id";
    $result = mysqli_query($conn, $query);
    
    // Display product information
    while($row = mysqli_fetch_assoc($result)) {
        echo "Product Name: " . $row['name'] . "<br>";
        echo "Price: $" . $row['price'] . "<br>";
        // Add more product details as needed
    }
    
    // Close database connection
    mysqli_close($conn);
}
?>