質問編集履歴
2
文章の内容変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,13 +10,13 @@
|
|
10
10
|
|
11
11
|
商品登録ボタンを押しても登録されません。
|
12
12
|
|
13
|
-
定義自体は
|
13
|
+
定義自体はしてると思っております。
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
|
17
|
-
![イメージ説明](
|
15
|
+
![イメージ説明](d01f427e9fe90ad750126373ecd1e278.png)
|
18
|
-
|
16
|
+
|
19
|
-
![イメージ説明](
|
17
|
+
![イメージ説明](563eddb1a55e760d4a4169613a5cb977.png)
|
18
|
+
|
19
|
+
|
20
20
|
|
21
21
|
```php
|
22
22
|
|
@@ -26,403 +26,303 @@
|
|
26
26
|
|
27
27
|
<?php
|
28
28
|
|
29
|
-
require_once('../../include/conf/const.php');
|
30
|
-
|
31
|
-
require_once('../../htdocs/mvc/tool.php');
|
32
|
-
|
33
|
-
require_once('../../htdocs/mvc/index.php');
|
34
|
-
|
35
|
-
require_once('../../htdocs/mvc/result.php');
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
$uploaddir = './drink_picture/';
|
40
|
-
|
41
29
|
$err_msg = [];
|
42
30
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
31
|
+
|
32
|
+
|
33
|
+
function insert_drink($link) {
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $_POST['sql_kind'] === 'insert') {
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
if (isset($_POST['new_name']) === TRUE) {
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
switch (TRUE) {
|
46
|
+
|
47
|
+
case ($_POST['new_name'] === ''):
|
48
|
+
|
49
|
+
$err_msg[] = '商品名を入力してください';
|
50
|
+
|
51
|
+
break;
|
52
|
+
|
53
|
+
case ($_POST['new_name'] === NULL);
|
54
|
+
|
55
|
+
$err_msg[] = '商品名を入力してください';
|
56
|
+
|
57
|
+
break;
|
58
|
+
|
59
|
+
default:
|
60
|
+
|
61
|
+
$new_name = $_POST['new_name'];
|
62
|
+
|
63
|
+
break;
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
if (isset($_POST['new_price']) === TRUE) {
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
switch (TRUE) {
|
76
|
+
|
77
|
+
case ($_POST['new_price'] === ''):
|
78
|
+
|
79
|
+
$err_msg[] = '値段を入力してください';
|
80
|
+
|
81
|
+
break;
|
82
|
+
|
83
|
+
case ($_POST['new_price'] === NULL):
|
84
|
+
|
85
|
+
$err_msg[] = '値段を入力してください';
|
86
|
+
|
87
|
+
break;
|
88
|
+
|
89
|
+
case (preg_match('/^[0-9]+$/', $_POST['new_price']) !== 1):
|
90
|
+
|
91
|
+
$err_msg[] = '値段は0以上の半角整数を入力してください';
|
92
|
+
|
93
|
+
break;
|
94
|
+
|
95
|
+
default:
|
96
|
+
|
97
|
+
$new_price = $_POST['new_price'];
|
98
|
+
|
99
|
+
break;
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
if (isset($_POST['new_stock']) === TRUE) {
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
switch (TRUE) {
|
112
|
+
|
113
|
+
case ($_POST['new_stock'] === ''):
|
114
|
+
|
115
|
+
$err_msg[] = '個数を入力してください';
|
116
|
+
|
117
|
+
break;
|
118
|
+
|
119
|
+
case ($_POST['new_stock'] === NULL):
|
120
|
+
|
121
|
+
$err_msg[] = '個数を入力してください';
|
122
|
+
|
123
|
+
break;
|
124
|
+
|
125
|
+
case (preg_match('/^[0-9]+$/', $_POST['new_stock']) !== 1):
|
126
|
+
|
127
|
+
$err_msg[] = '在庫は0以上の半角整数を入力してください';
|
128
|
+
|
129
|
+
break;
|
130
|
+
|
131
|
+
default:
|
132
|
+
|
133
|
+
$new_stock = $_POST['new_stock'];
|
134
|
+
|
135
|
+
break;
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
if ($_FILES['new_img']['error'] === UPLOAD_ERR_OK) {
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
if (count($err_msg) === 0) {
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
$chk_picture = getimagesize($_FILES['new_img']['tmp_name']);
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
if ($chk_picture['mime'] === 'image/png' || $chk_picture['mime'] === 'image/jpeg') {
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
if ($chk_picture[0] <= 500 && ($chk_picture[1] <= 500)) {
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
$mime = $chk_picture['mime'];
|
164
|
+
|
165
|
+
switch ($mime) {
|
166
|
+
|
167
|
+
case 'image/png':
|
168
|
+
|
169
|
+
$type = '.png';
|
170
|
+
|
171
|
+
break;
|
172
|
+
|
173
|
+
case 'image/jpeg':
|
174
|
+
|
175
|
+
$type = '.jpg';
|
176
|
+
|
177
|
+
break;
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
$upload = $uploaddir . date('YmdHis') . rand(0, 10000) . $type;
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
move_uploaded_file($_FILES['new_img']['tmp_name'], $upload);
|
188
|
+
|
189
|
+
} else {
|
190
|
+
|
191
|
+
$err_msg[] = 'ファイルは縦と横500px以内にしてください';
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
} else {
|
196
|
+
|
197
|
+
$err_msg[] = 'PNGかJPEG形式のファイルをアップロードしてください';
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
} else {
|
204
|
+
|
205
|
+
$err_msg[] = 'ファイルを選択してください';
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
if (isset($_POST['new_status']) === TRUE) {
|
214
|
+
|
215
|
+
if ((int) $_POST['new_status'] === 0 || (int) $_POST['new_status'] === 1) {
|
216
|
+
|
217
|
+
$new_status = (int) $_POST['new_status'];
|
218
|
+
|
219
|
+
} else {
|
220
|
+
|
221
|
+
$err_msg[] = 'ステータスは公開か非公開を選択してください';
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
} else {
|
226
|
+
|
227
|
+
$err_msg[] = 'ステータスを選択してください';
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
if (count($err_msg) === 0) {
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
$new_time = date('Y-m-d H:i:s');
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
$insert_data_info = [
|
242
|
+
|
243
|
+
'drink_name' => $new_name,
|
244
|
+
|
245
|
+
'price' => $new_price,
|
246
|
+
|
247
|
+
'created_at' => $new_time,
|
248
|
+
|
249
|
+
'updated_at' => $new_time,
|
250
|
+
|
251
|
+
'status' => $new_status,
|
252
|
+
|
253
|
+
'path' => $upload
|
254
|
+
|
255
|
+
];
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
$sql = 'INSERT INTO drink_info_table(drink_name, price, created_at, updated_at, status, path)VALUES(\''.$new_name.'\',\''.$new_price.'\',\''.$new_time.'\',\''.$new_time.'\',\''.$new_status.'\'\''.$upload.'\')';
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
if ($result = mysqli_query($link, $sql) === TRUE) {
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
$drink_id = mysqli_insert_id($link);
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
$insert_data_stock = [
|
272
|
+
|
273
|
+
'drink_id' => $drink_id,
|
274
|
+
|
275
|
+
'stock' => $new_stock,
|
276
|
+
|
277
|
+
'created_at' => $new_time,
|
278
|
+
|
279
|
+
'updated_at' => $new_time
|
280
|
+
|
281
|
+
];
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
$sql = 'INSERT INTO stock_table(drink_id, stock, created_at, updated_at)VALUES(\''.$drink_id.'\',\''.$new_stock.'\',\''.$new_time.'\',\''.$new_time.'\')';
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
if ($result = mysqli_query($link, $sql) !== TRUE) {
|
290
|
+
|
291
|
+
$err_msg[] = 'stock_tableへのデータの登録に失敗しました';
|
292
|
+
|
293
|
+
}
|
294
|
+
|
295
|
+
} else {
|
296
|
+
|
297
|
+
$err_msg[] = 'drink_info_tableへのデータの登録に失敗しました';
|
298
|
+
|
299
|
+
}
|
300
|
+
|
301
|
+
if (count($err_msg) === 0) {
|
302
|
+
|
303
|
+
$complete_msg[] = '追加登録完了!';
|
304
|
+
|
305
|
+
}
|
306
|
+
|
307
|
+
}
|
54
308
|
|
55
309
|
}
|
56
310
|
|
57
|
-
|
58
|
-
|
59
|
-
|
311
|
+
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
return $link;
|
64
312
|
|
65
313
|
}
|
66
314
|
|
67
315
|
|
68
316
|
|
69
|
-
function close_db_connect($link) {
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
mysqli_close($link);
|
74
|
-
|
75
|
-
}
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
function insert_drink($link) {
|
80
|
-
|
81
|
-
$new_time = date('Y-m-d H:i:s');
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
$insert_data_info = [
|
86
|
-
|
87
|
-
'drink_id' => $drink_id,
|
88
|
-
|
89
|
-
'drink_name' => $new_name,
|
90
|
-
|
91
|
-
'price' => $new_price,
|
92
|
-
|
93
|
-
'created_at' => $new_time,
|
94
|
-
|
95
|
-
'updated_at' => $new_time,
|
96
|
-
|
97
|
-
'status' => $new_status,
|
98
|
-
|
99
|
-
'path' => $paths,
|
100
|
-
|
101
|
-
];
|
102
|
-
|
103
|
-
print_r($insert_data_info);
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
$sql = 'INSERT INTO drink_info_table(drink_name, price, created_at, updated_at, status) VALUES(\''.$drink_id.'\',\''.$new_name.'\',\''.$new_price.'\',\''.$new_time.'\',\''.$new_time.'\',\''.$new_status.'\',\''.$paths.'\')';
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
if ($result = mysqli_query($link, $sql) === TRUE) {
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
$drink_id = mysqli_insert_id($link);
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
$insert_data_stock = [
|
120
|
-
|
121
|
-
'drink_id' => $drink_id,
|
122
|
-
|
123
|
-
'stock' => $new_stock,
|
124
|
-
|
125
|
-
'created_at' => $new_time,
|
126
|
-
|
127
|
-
'updated_at' => $new_time
|
128
|
-
|
129
|
-
];
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
$sql = 'INSERT INTO stock_table(drink_id, stock, created_at, updated_at) VALUES(\''.$drink_id.'\',\''.$new_stock.'\',\''.$new_time.'\',\''.$new_time.'\')';
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
if ($result = mysqli_query($link, $sql) !== TRUE) {
|
138
|
-
|
139
|
-
$err_msg[] = 'stock_tableへのデータの登録に失敗しました';
|
140
|
-
|
141
|
-
}
|
142
|
-
|
143
|
-
} else {
|
144
|
-
|
145
|
-
$err_msg[] = 'drink_info_tableへのデータの登録に失敗しました';
|
146
|
-
|
147
|
-
}
|
148
|
-
|
149
|
-
$complete_msg[] = '追加登録完了!';
|
150
|
-
|
151
|
-
}
|
152
|
-
|
153
317
|
|
154
318
|
|
155
319
|
```
|
156
320
|
|
157
|
-
```
|
158
|
-
|
159
|
-
tool.php
|
160
|
-
|
161
|
-
<?php
|
162
|
-
|
163
|
-
require_once('../../include/model/functions.php');
|
164
|
-
|
165
|
-
require_once('../../include/conf/const.php');
|
166
|
-
|
167
|
-
require_once('../../include/view/tool2.php');
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
$data = [ 'drink_id' => '',
|
172
|
-
|
173
|
-
'drink_name' => '',
|
174
|
-
|
175
|
-
'price' => '',
|
176
|
-
|
177
|
-
'created_at' => '',
|
178
|
-
|
179
|
-
'updated_at' => '',
|
180
|
-
|
181
|
-
'status' => '',
|
182
|
-
|
183
|
-
'path' => ''
|
184
|
-
|
185
|
-
];
|
186
|
-
|
187
|
-
$link = get_db_connect();
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
$data = insert_drink($link);
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
close_db_connect($link);
|
196
|
-
|
197
|
-
```
|
198
|
-
|
199
|
-
```
|
200
|
-
|
201
|
-
tool2.php
|
202
|
-
|
203
|
-
<!DOCTYPE html>
|
204
|
-
|
205
|
-
<html lang="ja">
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
<head>
|
210
|
-
|
211
|
-
<meta charset="UTF-8">
|
212
|
-
|
213
|
-
<title>自動販売機商品管理</title>
|
214
|
-
|
215
|
-
</head>
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
<body>
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
<?php if (count($complete_msg) !== 0) {
|
224
|
-
|
225
|
-
foreach ($complete_msg as $complete) { ?>
|
226
|
-
|
227
|
-
<p><?php print $complete; ?></p>
|
228
|
-
|
229
|
-
<?php }
|
230
|
-
|
231
|
-
} ?>
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
<?php if (count($err_msg) !== 0) {
|
236
|
-
|
237
|
-
foreach ($err_msg as $err) { ?>
|
238
|
-
|
239
|
-
<p><?php print $err; ?></p>
|
240
|
-
|
241
|
-
<?php }
|
242
|
-
|
243
|
-
} ?>
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
<h1>自動販売機管理ツール</h1>
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
<section>
|
252
|
-
|
253
|
-
<h2>新規商品追加</h2>
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
<form action="tool.php" method="post" enctype="multipart/form-data">
|
258
|
-
|
259
|
-
<label>名前: <input type="text" name="new_name" size="30" /></label><br>
|
260
|
-
|
261
|
-
<label>値段: <input type="text" name="new_price" size="30" /></label><br>
|
262
|
-
|
263
|
-
<label>個数: <input type="text" name="new_stock" size="30" /></label><br>
|
264
|
-
|
265
|
-
<input type="file" name="new_img" accept="image/jpeg, image/png, image/gif" /><br>
|
266
|
-
|
267
|
-
<select name="new_status"><br>
|
268
|
-
|
269
|
-
<option value="0">非公開</option>
|
270
|
-
|
271
|
-
<option value="1">公開</option>
|
272
|
-
|
273
|
-
<option value="2">入力チェック用</option>
|
274
|
-
|
275
|
-
</select><br>
|
276
|
-
|
277
|
-
<input type="hidden" name="sql_kind" value="insert">
|
278
|
-
|
279
|
-
<input type="submit" value="■□■□商品追加■□■□" />
|
280
|
-
|
281
|
-
</form>
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
</section>
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
<section>
|
290
|
-
|
291
|
-
<h2>商品情報変更</h2>
|
292
|
-
|
293
|
-
<table>
|
294
|
-
|
295
|
-
<caption>商品一覧</caption>
|
296
|
-
|
297
|
-
<tbody>
|
298
|
-
|
299
|
-
<tr>
|
300
|
-
|
301
|
-
<th>商品画像</th>
|
302
|
-
|
303
|
-
<th>商品名</th>
|
304
|
-
|
305
|
-
<th>価格</th>
|
306
|
-
|
307
|
-
<th>在庫数</th>
|
308
|
-
|
309
|
-
<th>ステータス</th>
|
310
|
-
|
311
|
-
</tr>
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
<?php if (empty($data) !== TRUE) {
|
316
|
-
|
317
|
-
foreach ($data as $list) {
|
318
|
-
|
319
|
-
if ((int) $list['status'] === 0) { ?>
|
320
|
-
|
321
|
-
<tr class="status_0">
|
322
|
-
|
323
|
-
<?php } else { ?>
|
324
|
-
|
325
|
-
<tr>
|
326
|
-
|
327
|
-
<?php } ?>
|
328
|
-
|
329
|
-
<td><img class="image" src="<?PHP print $list['path']; ?>"></td>
|
330
|
-
|
331
|
-
<? php print $list; ?>
|
332
|
-
|
333
|
-
<td class="d_name"><?php print html_enc($list['drink_name']); ?></td>
|
334
|
-
|
335
|
-
<td class="d_price"><?php print $list['price']; ?></td>
|
336
|
-
|
337
|
-
<td>
|
338
|
-
|
339
|
-
<form method="post">
|
340
|
-
|
341
|
-
<input type="text" class="input_text_width text_align_right" name="update_stock" value="<?php print $list['stock']; ?>">個
|
342
|
-
|
343
|
-
<br>
|
344
|
-
|
345
|
-
<input type="submit" value="変更">
|
346
|
-
|
347
|
-
<input type="hidden" name="drink_id" value="<?php print $list['drink_id']; ?>">
|
348
|
-
|
349
|
-
<input type="hidden" name="sql_kind" value="update">
|
350
|
-
|
351
|
-
</form>
|
352
|
-
|
353
|
-
</td>
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
<?php if ((int) $list['status'] === 0) { ?>
|
358
|
-
|
359
|
-
<td class="d_status">
|
360
|
-
|
361
|
-
<form method="post">
|
362
|
-
|
363
|
-
<input type="submit" value="非公開 → 公開">
|
364
|
-
|
365
|
-
<input type="hidden" name="change_status" value="1">
|
366
|
-
|
367
|
-
<input type="hidden" name="drink_id" value="<?php print $list['drink_id']; ?>">
|
368
|
-
|
369
|
-
<input type="hidden" name="sql_kind" value="change">
|
370
|
-
|
371
|
-
</form>
|
372
|
-
|
373
|
-
</td>
|
374
|
-
|
375
|
-
</tr>
|
376
|
-
|
377
|
-
<?php } else { ?>
|
378
|
-
|
379
|
-
<td class="d_status">
|
380
|
-
|
381
|
-
<form method="post">
|
382
|
-
|
383
|
-
<input type="submit" value="公開 → 非公開">
|
384
|
-
|
385
|
-
<input type="hidden" name="change_status" value="0">
|
386
|
-
|
387
|
-
<input type="hidden" name="drink_id" value="<?php print $list['drink_id']; ?>">
|
388
|
-
|
389
|
-
<input type="hidden" name="sql_kind" value="change">
|
390
|
-
|
391
|
-
</form>
|
392
|
-
|
393
|
-
</td>
|
394
|
-
|
395
|
-
</tr>
|
396
|
-
|
397
|
-
<?php }
|
398
|
-
|
399
|
-
}
|
400
|
-
|
401
|
-
} ?>
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
</tbody>
|
406
|
-
|
407
|
-
</table>
|
408
|
-
|
409
|
-
</section>
|
410
|
-
|
411
|
-
</body>
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
</html>
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
```
|
420
|
-
|
421
321
|
|
422
322
|
|
423
323
|
#試したこと
|
424
324
|
|
425
|
-
定義のやり
|
325
|
+
変数の定義のやり方を変えたりしましたが、エラーは直らなかったです。
|
426
326
|
|
427
327
|
|
428
328
|
|
1
画像追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,6 +14,10 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
|
17
|
+
![イメージ説明](983f00fa4959ddf31e125db603e04cb6.png)
|
18
|
+
|
19
|
+
![イメージ説明](685616b73e5a78458829e81708ea6528.png)
|
20
|
+
|
17
21
|
```php
|
18
22
|
|
19
23
|
ソースコード
|