質問編集履歴

2

update.phpの追加

2021/02/25 14:43

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -156,6 +156,198 @@
156
156
 
157
157
  <?php if(empty($_POST['name']) || mb_strlen($_POST['name']) > 10): ?>
158
158
 
159
+ 以下略
160
+
161
+ <div class="f-title f-bottom">
162
+
163
+ <h3>お問い合わせ内容をご記入ください<label class="kome">*</label></h3>
164
+
165
+ </div>
166
+
167
+ <div class="vali"><?php echo $errors['contact']; ?></div>
168
+
169
+ <div class="mb-3">
170
+
171
+ <textarea id="contact" name="contact" rows="7"><?php if(isset($_SESSION['contact'])){echo $_SESSION['contact'];} ?></textarea>
172
+
173
+ </div>
174
+
175
+ <input type="hidden" name="csrf_token" value="<?php echo setToken(); ?>">
176
+
177
+ <button type="submit" class="btn" name="btn_confirm">送信</button>
178
+
179
+ <?php endif; ?>
180
+
181
+ </form>
182
+
183
+ </div>
184
+
185
+ </div>
186
+
187
+ </div>
188
+
189
+ <table>
190
+
191
+ <tr>
192
+
193
+ <th>氏名</th>
194
+
195
+ <th>フリガナ</th>
196
+
197
+ <th>電話番号</th>
198
+
199
+ <th>メールアドレス</th>
200
+
201
+ <th>お問い合わせ内容</th>
202
+
203
+ </tr>
204
+
205
+ <?php foreach($result as $col): ?>
206
+
207
+ <tr>
208
+
209
+ <td><?php echo $col['name'] ?></td>
210
+
211
+ <td><?php echo $col['kana'] ?></td>
212
+
213
+ <td><?php echo $col['tel'] ?></td>
214
+
215
+ <td><?php echo $col['email'] ?></td>
216
+
217
+ <td><?php echo $col['body'] ?></td>
218
+
219
+ <td><a href="edit.php?id=<?php echo $col['id']; ?>">編集</a></td>
220
+
221
+ <td><a href="delete.php?id=<?php echo $col['id']; ?>">削除</a></td>
222
+
223
+ </tr>
224
+
225
+ <?php endforeach; ?>
226
+
227
+ </table>
228
+
229
+ <?php include("../common/footer.php"); ?>
230
+
231
+ </body>
232
+
233
+ </html>
234
+
235
+ ```
236
+
237
+
238
+
239
+ 編集フォーム
240
+
241
+ edit.php
242
+
243
+ ```
244
+
245
+ <?php
246
+
247
+ session_start();
248
+
249
+
250
+
251
+ // XSS対策
252
+
253
+ function h($s) {
254
+
255
+ return htmlspecialchars($s, ENT_QUOTES, "UTF-8");
256
+
257
+ }
258
+
259
+
260
+
261
+ // CSRF対策
262
+
263
+ function setToken() {
264
+
265
+ session_start();
266
+
267
+ $csrf_token = bin2hex(random_bytes(32));
268
+
269
+ $_SESSION['csrf_token'] = $csrf_token;
270
+
271
+
272
+
273
+ return $csrf_token;
274
+
275
+ }
276
+
277
+ ?>
278
+
279
+
280
+
281
+ <html lang="en">
282
+
283
+ <head>
284
+
285
+ <meta charset="UTF-8">
286
+
287
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
288
+
289
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
290
+
291
+ <link rel="stylesheet" href="contact.css">
292
+
293
+ <link rel="stylesheet" href="../common/header.css">
294
+
295
+ <link rel="stylesheet" href="../common/footer.css">
296
+
297
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
298
+
299
+ <script src="../public/js/header.js"></script>
300
+
301
+ <script src="../public/js/header2.js"></script>
302
+
303
+ <script src="../public/js/val.js"></script>
304
+
305
+ <title>JOBPOP</title>
306
+
307
+ </head>
308
+
309
+ <body>
310
+
311
+ <div class="contact-wrapper">
312
+
313
+ <div class="container">
314
+
315
+ <div class="top-title">
316
+
317
+ <h2>お問い合わせ</h2>
318
+
319
+ </div>
320
+
321
+ <div class="form-contents">
322
+
323
+ <div class="f-title">
324
+
325
+ <h3>下記の項目をご記入の上送信ボタンを押してください</h3>
326
+
327
+ </div>
328
+
329
+ <p class="text">
330
+
331
+ 送信頂いた件につきましては、当社より折り返しご連絡差し上げます。<br>
332
+
333
+ なお、ご連絡までに、お時間頂く場合もございますので予めご了承ください。<br>
334
+
335
+ <label class="kome">*</label>は必須項目になります。
336
+
337
+ </p>
338
+
339
+ <form action="update.php" method="POST">
340
+
341
+ <?php if(isset($_POST)): ?>
342
+
343
+ <div class="mb-3">
344
+
345
+ <input type="hidden" name="id" value="<?php if (!empty($_GET['id'])) echo(h($_GET['id'], ENT_QUOTES, 'UTF-8'));?>">
346
+
347
+ <label>氏名</label><label class="kome">*</label><br>
348
+
349
+ <?php if(empty($_POST['name']) || mb_strlen($_POST['name']) > 10): ?>
350
+
159
351
  <div class="vali"><?php echo $errors['name']; ?></div>
160
352
 
161
353
  <?php endif; ?>
@@ -222,46 +414,6 @@
222
414
 
223
415
  </div>
224
416
 
225
- <table>
226
-
227
- <tr>
228
-
229
- <th>氏名</th>
230
-
231
- <th>フリガナ</th>
232
-
233
- <th>電話番号</th>
234
-
235
- <th>メールアドレス</th>
236
-
237
- <th>お問い合わせ内容</th>
238
-
239
- </tr>
240
-
241
- <?php foreach($result as $col): ?>
242
-
243
- <tr>
244
-
245
- <td><?php echo $col['name'] ?></td>
246
-
247
- <td><?php echo $col['kana'] ?></td>
248
-
249
- <td><?php echo $col['tel'] ?></td>
250
-
251
- <td><?php echo $col['email'] ?></td>
252
-
253
- <td><?php echo $col['body'] ?></td>
254
-
255
- <td><a href="edit.php?id=<?php echo $col['id']; ?>">編集</a></td>
256
-
257
- <td><a href="delete.php?id=<?php echo $col['id']; ?>">削除</a></td>
258
-
259
- </tr>
260
-
261
- <?php endforeach; ?>
262
-
263
- </table>
264
-
265
417
  <?php include("../common/footer.php"); ?>
266
418
 
267
419
  </body>
@@ -272,17 +424,13 @@
272
424
 
273
425
 
274
426
 
275
- 編集フォーム
276
-
277
- edit.php
427
+ update.php
278
428
 
279
429
  ```
280
430
 
281
431
  <?php
282
432
 
283
- session_start();
433
+ session_start();
284
-
285
- var_dump($col['name']);
286
434
 
287
435
 
288
436
 
@@ -336,17 +484,17 @@
336
484
 
337
485
  $stmt = $dbh->prepare('UPDATE contacts SET name = :name, kana = :kana, tel = :tel, email = :email, body = :body WHERE id = :id');
338
486
 
339
- $stmt->bindValue(':id', $_GET['id'], PDO::PARAM_INT);
487
+ $stmt->bindValue(':id', $_POST['id'], PDO::PARAM_INT);
340
-
488
+
341
- $stmt->bindValue(":name", $_GET['name'], PDO::PARAM_STR);
489
+ $stmt->bindValue(":name", $_POST['name'], PDO::PARAM_STR);
342
-
490
+
343
- $stmt->bindValue(":kana", $_GET['kana'], PDO::PARAM_STR);
491
+ $stmt->bindValue(":kana", $_POST['kana'], PDO::PARAM_STR);
344
-
492
+
345
- $stmt->bindValue(":tel", $_GET['tel'], PDO::PARAM_INT);
493
+ $stmt->bindValue(":tel", $_POST['tel'], PDO::PARAM_INT);
346
-
494
+
347
- $stmt->bindValue(":email", $_GET['email'], PDO::PARAM_STR);
495
+ $stmt->bindValue(":email", $_POST['email'], PDO::PARAM_STR);
348
-
496
+
349
- $stmt->bindValue(":body", $_GET['body'], PDO::PARAM_STR);
497
+ $stmt->bindValue(":body", $_POST['contact'], PDO::PARAM_STR);
350
498
 
351
499
  $stmt->execute();
352
500
 
@@ -364,151 +512,13 @@
364
512
 
365
513
 
366
514
 
367
-
368
-
369
515
  ?>
370
516
 
371
517
 
372
518
 
373
- <html lang="en">
374
-
375
- <head>
519
+ 更新しました
376
-
377
- <meta charset="UTF-8">
520
+
378
-
379
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
380
-
381
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
382
-
383
- <link rel="stylesheet" href="contact.css">
384
-
385
- <link rel="stylesheet" href="../common/header.css">
386
-
387
- <link rel="stylesheet" href="../common/footer.css">
388
-
389
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
390
-
391
- <script src="../public/js/header.js"></script>
392
-
393
- <script src="../public/js/header2.js"></script>
394
-
395
- <script src="../public/js/val.js"></script>
396
-
397
- <title>JOBPOP</title>
398
-
399
- </head>
400
-
401
- <body>
402
-
403
- <div class="contact-wrapper">
404
-
405
- <div class="container">
406
-
407
- <div class="top-title">
408
-
409
- <h2>お問い合わせ</h2>
410
-
411
- </div>
412
-
413
- <div class="form-contents">
414
-
415
- <div class="f-title">
416
-
417
- <h3>下記の項目をご記入の上送信ボタンを押してください</h3>
418
-
419
- </div>
420
-
421
- <p class="text">
422
-
423
- 送信頂いた件につきましては、当社より折り返しご連絡差し上げます。<br>
424
-
425
- なお、ご連絡までに、お時間頂く場合もございますので予めご了承ください。<br>
426
-
427
- <label class="kome">*</label>は必須項目になります。
428
-
429
- </p>
430
-
431
- <form action="update.php" method="POST">
521
+ <a href="contact.php">お問い合わせへ</a>
432
-
433
- <?php if(isset($_POST)): ?>
434
-
435
- <div class="mb-3">
436
-
437
- <label>氏名</label><label class="kome">*</label><br>
438
-
439
- <?php if(empty($_POST['name']) || mb_strlen($_POST['name']) > 10): ?>
440
-
441
- <div class="vali"><?php echo $errors['name']; ?></div>
442
-
443
- <?php endif; ?>
444
-
445
- <input type="text" id="f-name" name="name" value="<?php if(isset($_SESSION['name'])){echo $_SESSION['name'];} ?>" placeholder="山田太郎">
446
-
447
- </div>
448
-
449
- <div class="mb-3">
450
-
451
- <label>フリガナ</label><label class="kome">*</label><br>
452
-
453
- <div class="vali"><?php echo $errors['kana']; ?></div>
454
-
455
- <input type="text" id="f-kana" name="kana" value="<?php if(isset($_SESSION['kana'])){echo $_SESSION['kana'];} ?>" placeholder="ヤマダタロウ">
456
-
457
- </div>
458
-
459
- <div class="mb-3">
460
-
461
- <label>電話番号</label><br>
462
-
463
- <div class="vali"><?php echo $errors['tel']; ?></div>
464
-
465
- <input type="text" id="f-tel" name="tel" value="<?php if(isset($_SESSION['tel'])){echo $_SESSION['tel'];} ?>" placeholder="09012345678">
466
-
467
- </div>
468
-
469
- <div class="mb-3">
470
-
471
- <label>メールアドレス</label><label class="kome">*</label><br>
472
-
473
- <div class="vali"><?php echo $errors['email']; ?></div>
474
-
475
- <input type="text" id="f-email" name="email" value="<?php if(isset($_SESSION['email'])){echo $_SESSION['email'];} ?>" placeholder="test@test.co.jp">
476
-
477
- </div>
478
-
479
- <div class="f-title f-bottom">
480
-
481
- <h3>お問い合わせ内容をご記入ください<label class="kome">*</label></h3>
482
-
483
- </div>
484
-
485
- <div class="vali"><?php echo $errors['contact']; ?></div>
486
-
487
- <div class="mb-3">
488
-
489
- <textarea id="contact" name="contact" rows="7"><?php if(isset($_SESSION['contact'])){echo $_SESSION['contact'];} ?></textarea>
490
-
491
- </div>
492
-
493
- <input type="hidden" name="csrf_token" value="<?php echo setToken(); ?>">
494
-
495
- <button type="submit" class="btn" name="btn_confirm">送信</button>
496
-
497
- <?php endif; ?>
498
-
499
- </form>
500
-
501
- </div>
502
-
503
- </div>
504
-
505
- </div>
506
-
507
- <?php include("../common/footer.php"); ?>
508
-
509
- </body>
510
-
511
- </html>
512
522
 
513
523
  ```
514
524
 

1

GETに変更

2021/02/25 14:43

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -338,7 +338,7 @@
338
338
 
339
339
  $stmt->bindValue(':id', $_GET['id'], PDO::PARAM_INT);
340
340
 
341
- $stmt->bindValue(":name", $col['name'], PDO::PARAM_STR);
341
+ $stmt->bindValue(":name", $_GET['name'], PDO::PARAM_STR);
342
342
 
343
343
  $stmt->bindValue(":kana", $_GET['kana'], PDO::PARAM_STR);
344
344