no message

This commit is contained in:
a-kizaki
2026-10-29 08:36:44 +09:00
commit a656ab0219
15 changed files with 2117 additions and 0 deletions

247
public/product_register.php Normal file
View File

@@ -0,0 +1,247 @@
<?php
require_once __DIR__ . '/../database/products/ProductAccess.php';
/**
* 商品登録処理(Create)
*
* このファイルでは、新しい商品をデータベースに登録します。
*/
// エラー表示設定(開発時のみ)
ini_set('display_errors', 1);
error_reporting(E_ALL);
$message = '';
$messageType = '';
// POSTリクエストの処理
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
try {
// TODO: ProductAccessのインスタンスを作成してください
$productAccess = null; // ここを実装
// TODO: POSTデータから商品情報を配列にまとめてください
// 必要な情報: category_id, name, description, price, stock
$productData = [
// ここにPOSTデータを設定
];
// TODO: productAccessのcreate()メソッドを呼び出して商品を登録してください
// 成功メッセージ
$message = "商品を登録しました!";
$messageType = "success";
} catch (Exception $e) {
// TODO: エラーメッセージを$messageに設定してください
$message = "";
$messageType = "error";
}
}
// カテゴリ一覧を取得(セレクトボックス用)
$categories = [];
try {
$productAccess = new ProductAccess();
$categories = $productAccess->getCategories();
} catch (Exception $e) {
$message = "カテゴリの取得に失敗しました: " . $e->getMessage();
$messageType = "error";
}
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>商品登録 - CRUD操作</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 600px;
margin: 0 auto;
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}
h1 {
color: #333;
margin-bottom: 10px;
font-size: 28px;
}
.subtitle {
color: #666;
margin-bottom: 25px;
font-size: 14px;
}
.nav-links {
display: flex;
gap: 10px;
margin-bottom: 25px;
flex-wrap: wrap;
}
.nav-links a {
padding: 8px 16px;
background: #667eea;
color: white;
text-decoration: none;
border-radius: 5px;
font-size: 14px;
transition: background 0.3s;
}
.nav-links a:hover {
background: #5568d3;
}
.message {
padding: 15px;
margin-bottom: 20px;
border-radius: 5px;
font-weight: bold;
}
.message.success {
background: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
}
.message.error {
background: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 5px;
color: #333;
font-weight: bold;
}
input[type="text"],
input[type="number"],
select,
textarea {
width: 100%;
padding: 10px;
border: 2px solid #ddd;
border-radius: 5px;
font-size: 14px;
transition: border-color 0.3s;
}
input[type="text"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus {
outline: none;
border-color: #667eea;
}
textarea {
resize: vertical;
min-height: 100px;
}
.btn {
width: 100%;
padding: 12px;
background: #667eea;
color: white;
border: none;
border-radius: 5px;
font-size: 16px;
font-weight: bold;
cursor: pointer;
transition: background 0.3s;
}
.btn:hover {
background: #5568d3;
}
</style>
</head>
<body>
<div class="container">
<h1>📝 商品登録</h1>
<p class="subtitle">Create - 新しい商品を登録します</p>
<div class="nav-links">
<a href="index.php">🏠 トップ</a>
<a href="product_list.php">📋 一覧表示</a>
<a href="product_update.php">✏️ 更新</a>
<a href="product_delete.php">🗑️ 削除</a>
<a href="product_join.php">🔗 JOIN検索</a>
</div>
<?php if ($message): ?>
<div class="message <?php echo $messageType; ?>">
<?php echo htmlspecialchars($message); ?>
</div>
<?php endif; ?>
<form method="POST" action="product_register.php">
<div class="form-group">
<label for="category_id">カテゴリ *</label>
<select name="category_id" id="category_id" required>
<option value="">選択してください</option>
<?php foreach ($categories as $category): ?>
<option value="<?php echo $category['id']; ?>">
<?php echo htmlspecialchars($category['name']); ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<label for="name">商品名 *</label>
<input type="text" name="name" id="name" required>
</div>
<div class="form-group">
<label for="description">説明</label>
<textarea name="description" id="description"></textarea>
</div>
<div class="form-group">
<label for="price">価格 *</label>
<input type="number" name="price" id="price" step="0.01" min="0" required>
</div>
<div class="form-group">
<label for="stock">在庫数 *</label>
<input type="number" name="stock" id="stock" min="0" required>
</div>
<button type="submit" class="btn">登録する</button>
</form>
</div>
</body>
</html>