質問編集履歴

1

phpの追加

2017/08/21 12:20

投稿

dog57
dog57

スコア131

test CHANGED
File without changes
test CHANGED
@@ -294,9 +294,261 @@
294
294
 
295
295
 
296
296
 
297
-
297
+ 変更画面
298
+
298
-
299
+ ```php
300
+
299
-
301
+ <?php
302
+
303
+
304
+
305
+ header("Content-type: text/html; charset=utf-8");
306
+
307
+
308
+
309
+ require_once("index_db.php");
310
+
311
+
312
+
313
+
314
+
315
+ if(empty($_POST)) {
316
+
317
+ echo "<a href='update1.php'>update1.php</a>←こちらのページからどうぞ";
318
+
319
+ exit();
320
+
321
+ }else{
322
+
323
+ if (!isset($_POST['id']) || !is_numeric($_POST['id']) ){
324
+
325
+ echo "IDエラー";
326
+
327
+ exit();
328
+
329
+ }else{
330
+
331
+ //プリペアドステートメント
332
+
333
+ $stmt = $mysqli->prepare("SELECT * FROM member WHERE id=?");
334
+
335
+ if ($stmt) {
336
+
337
+ //プレースホルダへ実際の値を設定する
338
+
339
+ $stmt->bind_param('i', $id);
340
+
341
+ $id = $_POST['id'];
342
+
343
+
344
+
345
+ //クエリ実行
346
+
347
+ $stmt->execute();
348
+
349
+
350
+
351
+ //結果変数のバインド
352
+
353
+ $stmt->bind_result($id,$nation);
354
+
355
+ // 値の取得
356
+
357
+ $stmt->fetch();
358
+
359
+
360
+
361
+ //ステートメント切断
362
+
363
+ $stmt->close();
364
+
365
+ }else{
366
+
367
+ echo $mysqli->errno . $mysqli->error;
368
+
369
+ }
370
+
371
+ }
372
+
373
+ }
374
+
375
+
376
+
377
+ // データベース切断
378
+
379
+ $pdo = null;
380
+
381
+
382
+
383
+ ?>
384
+
385
+
386
+
387
+ <!DOCTYPE html>
388
+
389
+ <html>
390
+
391
+ <head>
392
+
393
+ <title>変更画面</title>
394
+
395
+ </head>
396
+
397
+ <body>
398
+
399
+ <h1>変更画面</h1>
400
+
401
+
402
+
403
+ <p>名前を変更して下さい。</p>
404
+
405
+ <form action="update3.php" method="post">
406
+
407
+ <input type="text" name="name" value="<?=htmlspecialchars($name, ENT_QUOTES, 'UTF-8')?>">
408
+
409
+ <input type="hidden" name="id" value="<?=$id?>">
410
+
411
+ <input type="submit" value="変更する">
412
+
413
+ </form>
414
+
415
+
416
+
417
+ </body>
418
+
419
+ </html>
420
+
421
+
422
+
423
+ ```
424
+
425
+
426
+
427
+ 変更完了画面
428
+
429
+ ```php
430
+
431
+ <?php
432
+
433
+  
434
+
435
+ header("Content-type: text/html; charset=utf-8");
436
+
437
+  
438
+
439
+ require_once(“index_db.php");
440
+
441
+
442
+
443
+  
444
+
445
+ if(empty($_POST)) {
446
+
447
+ echo "<a href='update1.php'>update1.php</a>←こちらのページからどうぞ";
448
+
449
+ exit();
450
+
451
+ }else{
452
+
453
+ //名前入力チェック
454
+
455
+ if (!isset($_POST['name'])  || $_POST['name'] === "" ){
456
+
457
+ $errors['name'] = "名前が入力されていません。";
458
+
459
+ }
460
+
461
+
462
+
463
+ if(count($errors) === 0){
464
+
465
+ //プリペアドステートメント
466
+
467
+ $stmt = $mysqli->prepare("UPDATE nation SET nation=? WHERE id=?");
468
+
469
+ if ($stmt) {
470
+
471
+ //プレースホルダへ実際の値を設定する
472
+
473
+ $stmt->bind_param('si', $nation, $id);
474
+
475
+ $name = $_POST[‘nation’];
476
+
477
+ $id = $_POST['id'];
478
+
479
+
480
+
481
+ //クエリ実行
482
+
483
+ $stmt->execute();
484
+
485
+ //ステートメント切断
486
+
487
+ $stmt->close();
488
+
489
+ }else{
490
+
491
+ echo $mysqli->errno . $mysqli->error;
492
+
493
+ }
494
+
495
+ }
496
+
497
+ }
498
+
499
+  
500
+
501
+ // データベース切断
502
+
503
+ $mysqli->close();
504
+
505
+
506
+
507
+ ?>
508
+
509
+  
510
+
511
+ <!DOCTYPE html>
512
+
513
+ <html>
514
+
515
+ <head>
516
+
517
+ <title>変更画面</title>
518
+
519
+ </head>
520
+
521
+ <body>
522
+
523
+ <h1>変更画面</h1>
524
+
525
+  
526
+
527
+ <?php if (count($errors) === 0): ?>
528
+
529
+ <p>変更完了しました。</p>
530
+
531
+ <?php elseif(count($errors) > 0): ?>
532
+
533
+ <?php
534
+
535
+ foreach($errors as $value){
536
+
537
+ echo "<p>".$value."</p>";
538
+
539
+ }
540
+
541
+ ?>
542
+
543
+ <?php endif; ?>
544
+
545
+  
546
+
547
+ </body>
548
+
549
+ </html>
550
+
551
+ ```
300
552
 
301
553
  ###補足情報(言語/FW/ツール等のバージョンなど)
302
554