add this to git finally
This commit is contained in:
73
products.php
Normal file
73
products.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
include_once 'database.php';
|
||||
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
if ($method === 'POST') {
|
||||
if (isset($_POST['create'])) {
|
||||
$title = $_POST['title'];
|
||||
$amountInStock = $_POST['in_stock'];
|
||||
createProduct($title, $amountInStock);
|
||||
}
|
||||
} elseif ($method === 'GET') {
|
||||
if (isset($_GET["title"])) {
|
||||
$title = $_GET["title"];
|
||||
}
|
||||
if (!is_null($title)) {
|
||||
$products = getProductsByTitle($title);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($products)) {
|
||||
$products = getAllProducts();
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Products page</title>
|
||||
<link rel="stylesheet" href="index.css">
|
||||
</head>
|
||||
<body>
|
||||
<?php include 'header.php'; ?>
|
||||
<div id="product-forms">
|
||||
<div id="add-product">
|
||||
<h2>Add new Product</h2>
|
||||
<form method="POST">
|
||||
<label for "title">Title:</label>
|
||||
<input type="text" name="title" required>
|
||||
|
||||
<label for "in_stock">Amount in stock:</label>
|
||||
<input type="text" name="in_stock" required>
|
||||
|
||||
<br>
|
||||
<button type="submit" name="create">Create product</button>
|
||||
</form>
|
||||
</div>
|
||||
<div id="search-product-by-title">
|
||||
<h2>Find product by title</h2>
|
||||
<form method="GET" action="/products">
|
||||
<label for "title">Title:</label>
|
||||
<input type="text" name="title" required>
|
||||
|
||||
<br>
|
||||
<button type="submit">Search</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h2>Products:</h2>
|
||||
<?php if (empty($products)): ?>
|
||||
<p>No products found.</p>
|
||||
<?php else: ?>
|
||||
<?php foreach ($products as $prod): ?>
|
||||
<div class="product">
|
||||
<h3><?= $prod[1] ?></h3>
|
||||
<p>In stock: <?= $prod[2] ?> items</p>
|
||||
<p><strong>ID: <?= $prod[0] ?></strong></p>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user