118 lines
4.0 KiB
PHP
118 lines
4.0 KiB
PHP
<?php
|
|
$products = [
|
|
[
|
|
"name" => "Lean Beef Mince",
|
|
"image" => "assets/pasted-20251121-114725-33d5afd9.jpg",
|
|
"calories" => 150,
|
|
"protein" => 20,
|
|
"carbs" => 0,
|
|
"fat" => 7,
|
|
],
|
|
[
|
|
"name" => "Chicken Breast",
|
|
"image" => "assets/vm-shot-2025-11-21T11-47-05-928Z.jpg",
|
|
"calories" => 165,
|
|
"protein" => 31,
|
|
"carbs" => 0,
|
|
"fat" => 3.6,
|
|
],
|
|
[
|
|
"name" => "Salmon Fillet",
|
|
"image" => "https://images.pexels.com/photos/3296279/pexels-photo-3296279.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1",
|
|
"calories" => 208,
|
|
"protein" => 20,
|
|
"carbs" => 0,
|
|
"fat" => 13,
|
|
],
|
|
[
|
|
"name" => "Broccoli",
|
|
"image" => "https://images.pexels.com/photos/4057737/pexels-photo-4057737.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1",
|
|
"calories" => 55,
|
|
"protein" => 3.7,
|
|
"carbs" => 11,
|
|
"fat" => 0.6,
|
|
],
|
|
];
|
|
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
$success_message = "";
|
|
$error_message = "";
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
if (!empty($_POST['product_name']) && !empty($_POST['quantity']) && is_numeric($_POST['quantity'])) {
|
|
try {
|
|
$product_name = $_POST['product_name'];
|
|
$quantity = (int)$_POST['quantity'];
|
|
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("INSERT INTO sales (product_name, quantity) VALUES (?, ?)");
|
|
$stmt->execute([$product_name, $quantity]);
|
|
|
|
$success_message = "Successfully added $quantity sale(s) for $product_name!";
|
|
} catch (PDOException $e) {
|
|
$error_message = "Error: Could not record the sale. " . $e->getMessage();
|
|
}
|
|
} else {
|
|
$error_message = "Please fill out all fields correctly.";
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Add Sale - Sales Tracker</title>
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
</head>
|
|
<body>
|
|
|
|
<div class="mobile-container">
|
|
<header class="app-header">
|
|
<a href="index.php" class="back-button">←</a>
|
|
<h1>Add a New Sale</h1>
|
|
</header>
|
|
|
|
<main class="main-content">
|
|
<?php if ($success_message): ?>
|
|
<div class="alert success">
|
|
<?php echo $success_message; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($error_message): ?>
|
|
<div class="alert error">
|
|
<?php echo $error_message; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<form action="add_sale.php" method="POST" class="add-sale-form">
|
|
<div class="form-group">
|
|
<label for="product_name">Product</label>
|
|
<select id="product_name" name="product_name" required>
|
|
<option value="" disabled selected>Select a product</option>
|
|
<?php foreach ($products as $product): ?>
|
|
<option value="<?php echo htmlspecialchars($product['name']); ?>"><?php echo htmlspecialchars($product['name']); ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="quantity">Quantity</label>
|
|
<input type="number" id="quantity" name="quantity" min="1" value="1" required>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<button type="submit" class="btn btn-primary">Record Sale</button>
|
|
</div>
|
|
</form>
|
|
</main>
|
|
</div>
|
|
|
|
</body>
|
|
</html>
|