質問編集履歴
3
文言の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -24,6 +24,10 @@
|
|
24
24
|
|
25
25
|
|
26
26
|
|
27
|
+
・エラー時に入力した値は保持する
|
28
|
+
|
29
|
+
|
30
|
+
|
27
31
|
・赤字はcssを用意(これはわかるので大丈夫)
|
28
32
|
|
29
33
|
|
2
add.php の記載
test
CHANGED
File without changes
|
test
CHANGED
@@ -38,7 +38,7 @@
|
|
38
38
|
|
39
39
|
|
40
40
|
|
41
|
-
###
|
41
|
+
### form.php
|
42
42
|
|
43
43
|
|
44
44
|
|
@@ -304,6 +304,100 @@
|
|
304
304
|
|
305
305
|
|
306
306
|
|
307
|
+
###add.php
|
308
|
+
|
309
|
+
```PHP
|
310
|
+
|
311
|
+
<?php
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
$employee_num = (int)$_POST['employee_num'];
|
316
|
+
|
317
|
+
$employee_name = $_POST['employee_name'];
|
318
|
+
|
319
|
+
$sexual = (int)$_POST['sexual'];
|
320
|
+
|
321
|
+
$department = (int) $_POST['department'];
|
322
|
+
|
323
|
+
$year = $_POST['year'];
|
324
|
+
|
325
|
+
$month = $_POST['month'];
|
326
|
+
|
327
|
+
$day = $_POST['day'];
|
328
|
+
|
329
|
+
$select_month = sprintf('%02d', $month);
|
330
|
+
|
331
|
+
$select_day = sprintf('%02d', $day);
|
332
|
+
|
333
|
+
$total = $year.$select_month.$select_day;
|
334
|
+
|
335
|
+
$birthday = date("Y-m-d",strtotime($total));
|
336
|
+
|
337
|
+
$phone_num = $_POST['phone_num'];
|
338
|
+
|
339
|
+
$street = $_POST['street'];
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
require_once '\MAMP\db_config.php';
|
346
|
+
|
347
|
+
try
|
348
|
+
|
349
|
+
{
|
350
|
+
|
351
|
+
// DB接続
|
352
|
+
|
353
|
+
$dbh = new PDO('mysql:host=localhost;dbname=employee_db;charset=utf8', $user, $pass);
|
354
|
+
|
355
|
+
$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
356
|
+
|
357
|
+
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
358
|
+
|
359
|
+
$sql = "INSERT INTO employee (employee_num, employee_name, sexual, department, birthday, phone_num, street) VALUES (?, ?, ?, ?, ?, ?, ?)";
|
360
|
+
|
361
|
+
$stmt = $dbh->prepare($sql);
|
362
|
+
|
363
|
+
$stmt->bindValue(1, $employee_num, PDO::PARAM_INT);
|
364
|
+
|
365
|
+
$stmt->bindValue(2, $employee_name, PDO::PARAM_STR);
|
366
|
+
|
367
|
+
$stmt->bindValue(3, $sexual, PDO::PARAM_INT);
|
368
|
+
|
369
|
+
$stmt->bindValue(4, $department, PDO::PARAM_INT);
|
370
|
+
|
371
|
+
$stmt->bindValue(5, $birthday, PDO::PARAM_STR);
|
372
|
+
|
373
|
+
$stmt->bindValue(6, $phone_num, PDO::PARAM_STR);
|
374
|
+
|
375
|
+
$stmt->bindValue(7, $street, PDO::PARAM_STR);
|
376
|
+
|
377
|
+
$stmt->execute();
|
378
|
+
|
379
|
+
$dbh = null;
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
echo "社員の登録が完了しました。<br>";
|
384
|
+
|
385
|
+
echo "<a href='index.php'>トップページへ戻る</a>";
|
386
|
+
|
387
|
+
}
|
388
|
+
|
389
|
+
catch(Exception $e)
|
390
|
+
|
391
|
+
{
|
392
|
+
|
393
|
+
echo "エラー発生: " . htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8') . "<br>";
|
394
|
+
|
395
|
+
die();
|
396
|
+
|
397
|
+
}
|
398
|
+
|
399
|
+
```
|
400
|
+
|
307
401
|
### 試したこと
|
308
402
|
|
309
403
|
|
1
補足の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,6 +28,16 @@
|
|
28
28
|
|
29
29
|
|
30
30
|
|
31
|
+
|
32
|
+
|
33
|
+
補足
|
34
|
+
|
35
|
+
・ブートストラップはまだシートを当てただけで実装はしてないです。
|
36
|
+
|
37
|
+
・赤字は別にCSSを作成します
|
38
|
+
|
39
|
+
|
40
|
+
|
31
41
|
### 該当のソースコード
|
32
42
|
|
33
43
|
|