2016-04-16 2 views
0

[OK]ボタンを押したときにフィールドを設定するために、SQLデータベースからコンテンツを取得しようとしています。問題は、どのボタンが押されても、最後の行の値を常にphpに送ることです。私はPHP/MySQLのnoobです。これが尋ねられていたり、以前に答えられたことがお詫び申し上げます。私は何時間もサイトを検索していましたが、それを把握するのに役立つものは何も見つかりませんでした。ボタンがクリックされたときに間違った値が渡される理由

インデックスページの画像やコード:index page image

<?php 
require_once('database.php'); 

$query = 'SELECT * FROM omniarticles 
    ORDER BY recid'; 

$statement1 = $db->prepare($query); 
$statement1->execute(); 
$article = $statement1->fetchAll(); 
$statement1->closeCursor(); 
?> 
<!DOCTYPE HTML> 
<html> 
<head> 
    <title>AMS</title> 
    <link rel="stylesheet" type="text/css" href="basic.css"> 
</head> 
<body> 
    <h3>Article List</h3> 
    <table> 
     <tr> 
     <th>Publication Date</th> 
     <th>Title</th> 
     <th>Action</th> 
     </tr> 

     <?php foreach ($article as $articles) : ?> 
       <tr> 
        <td><?php echo $articles['publicationDate']; ?></td> 
        <td><?php echo $articles['title']; ?></td> 
        <td><form action="view.php" method="post"> 
          <input type="hidden" name="recid" 
            value="<?php echo $articles['recid'];?>"> 
          <input type="submit" value="View"> 
         <input type="submit" value="Edit"> 
        </td> 
       </tr> 
     <?php endforeach; ?> 
    </table> 
</body> 
</html> 

view.phpコード:

<?php 
$recid = filter_input(INPUT_POST, 'recid'); 

require_once('database.php'); 

$q = 'SELECT * FROM omniarticles 
    WHERE recid = :recid'; 
$s = $db->prepare($q); 
$s->bindValue(':recid', $recid); 
$s->execute(); 
$title = $s->fetch(); 
$s->closeCursor(); 

?> 

<!DOCTYPE HTML> 
<html> 
<head> 
    <title>AMS</title> 
    <link rel="stylesheet" type="text/css" href="Module5Lab.css"> 
</head> 
<body> 
     <label>Article Title</label> 
     <input type="text" name="article_title" value="<?php echo $title['recid']; ?>"/> 
     <br/> 
     <br/> 
     <label>Article Summary</label> 
     <textarea rows="4" cols="50"></textarea> 
     <br/> 
     <label>Article Content</label> 
     <textarea rows="20" cols="50"><?php echo $title['content']; ?></textarea> 
     <br/> 
     <label>Publication Date</label> 
     <input type="text" name="publication_date"/> 
     <br/> 
</body> 
</html> 

私は取得しています、結果に関係なく、私が押したボタン、最後のレコードのために常にではありません。 enter image description here

+2

ループ内でフォームタグを閉じるようにしてください。 – smerny

+0

もっとデバッグする必要がありますので、もっと情報が必要です。 –

+0

"echo $ recid;"を実行します。 –

答えて

0

問題はラインとほぼ確実である:

$ RECID = filter_input(INPUT_POST、 'RECID');

var_dump($ _ POST)を実行し、投稿データに何があるのか​​を確認することをおすすめします。

関連する問題