PR 15 PHP
PR 15 PHP
php
// Database Connec on
$host = "localhost";
$user = "root";
$pass = ""; // Default MySQL password (empty in XAMPP)
$dbname = "shop_db";
// Check connec on
if ($conn->connect_error) {
die("Connec on failed: " . $conn->connect_error);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
ini al-scale=1.0">
Product List
</head>
<body>
<h2 style="text-align:center;">Product List</h2>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Price ($)</th>
<th>Created At</th>
</tr>
<?php
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "<tr>
<td>{$row['id']}</td>
<td>{$row['name']}</td>
<td>{$row['price']}</td>
<td>{$row['created_at']}</td>
</tr>";
}
} else {
echo "<tr><td colspan='4'>No products
found</td></tr>";
}
?>
</table>
</body>
</html>
<?php
$conn->close();
?>
<?php </form>
// Database Connec on
</body>
$host = "localhost";
$user = "root"; </html>
$pass = ""; // Default MySQL password (empty in XAMPP)
$dbname = "shop_db";
// Check connec on
if ($conn->connect_error) {
die("Connec on failed: " . $conn->connect_error);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
ini al-scale=1.0">
Product List
</head>
<body>
<h2 style="text-align:center;">Product List</h2>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Price ($)</th>
<th>Created At</th>
</tr>
<?php
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "<tr>
<td>{$row['id']}</td>
<td>{$row['name']}</td>
<td>{$row['price']}</td>
<td>{$row['created_at']}</td>
</tr>";
}
} else {
echo "<tr><td colspan='4'>No products
found</td></tr>";
}
?>
</table>
</body>
</html>
<?php
$conn->close();
?>