27 lines
775 B
PHP
27 lines
775 B
PHP
<?php
|
|
require_once 'db/config.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$name = $_POST['name'] ?? null;
|
|
$description = $_POST['description'] ?? null;
|
|
$price = $_POST['price'] ?? null;
|
|
|
|
if ($name && $price) {
|
|
try {
|
|
$pdo = db();
|
|
$sql = "INSERT INTO items (name, description, price) VALUES (?, ?, ?)";
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute([$name, $description, $price]);
|
|
|
|
header("Location: items.php?success=1");
|
|
exit();
|
|
} catch (PDOException $e) {
|
|
header("Location: items.php?error=" . urlencode($e->getMessage()));
|
|
exit();
|
|
}
|
|
} else {
|
|
header("Location: items.php?error=invalid_input");
|
|
exit();
|
|
}
|
|
}
|
|
?>
|