0
[OK]ボタンを押したときにフィールドを設定するために、SQLデータベースからコンテンツを取得しようとしています。問題は、どのボタンが押されても、最後の行の値を常にphpに送ることです。私はPHP/MySQLのnoobです。これが尋ねられていたり、以前に答えられたことがお詫び申し上げます。私は何時間もサイトを検索していましたが、それを把握するのに役立つものは何も見つかりませんでした。ボタンがクリックされたときに間違った値が渡される理由
<?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>
私は取得しています、結果に関係なく、私が押したボタン、最後のレコードのために常にではありません。
ループ内でフォームタグを閉じるようにしてください。 – smerny
もっとデバッグする必要がありますので、もっと情報が必要です。 –
"echo $ recid;"を実行します。 –