PHPで編集機能を作成していますが、それぞれの編集画面にいけません。
トップ画面→編集画面→編集完了 という順番なのですが、
トップ画面の1位、2位、3位、4位、5位それぞれの編集画面にいけるようにしたいのですが、
どうようにしたらいけますか?
現状では、1位〜5位のどの編集リンクをクリックしても
編集画面では1位の内容が表示されます。
2位の編集リンクをクリックしたらちゃんと2位の編集内容が
3位の編集リンクをクリックしたらちゃんと3位の編集内容がでるようにさたいのですが
どのようにしたら良いでしょうか?
ご教授いただけると嬉しいです。
よろしくお願いします
トップ画面 index.php
php
1<?php 2ini_set("display_errors", 1); 3error_reporting(E_ALL); 4 5// 文字化け対策 6header("Content-type: text/html; charset=utf-8"); 7 8function h($string) { 9 return htmlspecialchars($string, ENT_QUOTES, "UTF-8"); 10} 11 12require_once(__DIR__. "/db.php"); 13 14//例外処理を投げる(スロー)ようにする 15$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 16 17$sql = "SELECT * FROM country"; 18$statement = $dbh->query($sql); 19 20// 結果の取得 21$country = array(); 22 23foreach ($statement as $row) { 24 $country[] = $row; 25} 26 27// データベース切断 28$dbh = null; 29 30 ?> 31 32<!DOCTYPE html> 33<html lang="ja"> 34 35<head> 36 <meta charset="utf-8"> 37 <title>行ってみたい国一覧</title> 38 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 39 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" media="screen"> 40 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css"> 41 <link href="org.css" rel="stylesheet" media="screen"> 42</head> 43 44<body> 45 46<!-- テーブル(表) --> 47 <div class="table-responsive" style="margin-top:60px;"> 48 <table id="table1" class="table table-hover"> 49 <form action="update.php" method="post" name="update"> 50 <!-- ここは基本記述 --> 51 <thead> 52 <tr> 53 <th>順位</th> 54 <th>国名</th> 55 <th>食べたい食べ物</th> 56 <th>理由</th> 57 <th></th> 58 </tr> 59 </thead> 60 61 <?php foreach ($country as $row) { 62 ?> 63 64 <tbody> 65 66 <tr> 67 <td><?php echo h($row["rank"]); ?></td> 68 <td><?php echo h($row["nation"]); ?></td> 69 <td><?php echo h($row["food"]); ?></td> 70 <td><?php echo h($row["reason"]); ?></td> 71 <td> 72 <a href="update.php" onclick="document.update.submit();return false;">編集</a> 73 <a href="#" onclick="document.リンク先.submit();return false;">削除</a> 74 </td> 75 76 <form action="update.php" method="post"> 77 <input type="hidden" name="rank" value="<?php echo $row["rank"]; ?>"> 78 <input type="hidden" name="nation" value="<?php echo $row["nation"]; ?>"> 79 <input type="hidden" name="food" value="<?php echo $row["food"]; ?>"> 80 <input type="hidden" name="reason" value="<?php echo $row["reason"]; ?>"> 81 </form> 82 </tr> 83 84 </tbody> 85 86 87 <?php 88 } 89 ?> 90 91 92 </table> 93 </div> 94 95<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 96 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> 97</body> 98 99</html>
編集画面 update.php
php
1<?php 2ini_set("display_errors", 1); 3error_reporting(E_ALL); 4 5// 文字化け対策 6header("Content-type: text/html; charset=UTF-8"); 7 8require_once(__DIR__. "/db.php"); 9 10 11 12$_SESSION["rank"] = filter_input(INPUT_POST, 'rank'); 13$_SESSION["nation"] = filter_input(INPUT_POST, 'nation'); 14$_SESSION["food"] = filter_input(INPUT_POST, 'food'); 15$_SESSION["reason"] = filter_input(INPUT_POST, 'reason'); 16 17 18 19function h($string) { 20 return htmlspecialchars($string, ENT_QUOTES, "UTF-8"); 21} 22 23 24?> 25 26<!DOCTYPE html> 27<html lang="ja"> 28 29<head> 30 <meta charset="utf-8"> 31 <title>編集画面</title> 32 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 33 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" media="screen"> 34 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css"> 35 <link href="org.css" rel="stylesheet" media="screen"> 36</head> 37 38<body> 39 40 41 <!-- テーブル(表) --> 42 <div class="table-responsive" style="margin-top:60px;"> 43 <table id="table1" class="table table-hover"> 44 <form action="#" method="post"> 45 <!-- ここは基本記述 --> 46 <thead> 47 <tr> 48 <th>順位</th> 49 <th>国名</th> 50 <th>食べたい食べ物</th> 51 <th>理由</th> 52 <th></th> 53 </tr> 54 </thead> 55 56 57 58 <tbody> 59 60 <tr> 61 <td><input type="text" name="rank" value="<?php echo h($_SESSION["rank"]); ?>"></td> 62 <td><input type="text" name="nation" value="<?php echo h($_SESSION["nation"]); ?>"></td> 63 <td><input type="text" name="food" value="<?php echo h($_SESSION["food"]); ?>"</td> 64 <td><input type="text" name="reason" value="<?php echo h($_SESSION["reason"]); ?>"></td> 65 <td> 66 <button type="button" class="btn btn-primary btn-xs">変更する</button> 67 </td> 68 </tr> 69 70 </tbody> 71 72 73 74 75 </form> 76 </table> 77 </div> 78 79 80 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 81 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> 82 </body> 83</html> 84
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/12/14 00:55 編集
2017/12/14 01:21
2017/12/14 01:31 編集
2017/12/14 01:41
2017/12/14 01:47
2017/12/14 01:52