product_details.php

 avatar
unknown
php
a year ago
1.2 kB
4
Indexable
<!DOCTYPE html>
<html>
<head>
    <title>Product Details</title>
</head>
<body>
    <h2>Product Details</h2>

    <?php
    // Database connection and other setup
    $hostname = "localhost"; 
    $username = "nhatkhang"; 
    $password = "872003";
    $dbname = "nhatkhang";

    $conn = mysqli_connect($hostname, $username, $password, $dbname);

    // Check connection
    if (!$conn) {
        die("Connection failed: " . mysqli_connect_error());
    }

    if (isset($_GET['id'])) {
        $id = $_GET['id'];
        $query = "SELECT * FROM products WHERE id = $id"; // Assuming 'products' is the table name

        $result = mysqli_query($conn, $query);
        if (mysqli_num_rows($result) > 0) {
            $row = mysqli_fetch_assoc($result);
            echo "<p>Product ID: " . $row['id'] . "</p>";
            echo "<p>Product Name: " . $row['product_name'] . "</p>";
            echo "<p>Price: $" . $row['price'] . "</p>";
            // Add more product details as needed
        } else {
            echo "<p>Product not found.</p>";
        }
    } else {
        echo "<p>Invalid product ID.</p>";
    }

    mysqli_close($conn);
    ?>
</body>
</html>
Editor is loading...
Leave a Comment