初投稿です。書き方に不備等がありましたら、申し訳ございません。
分からない点がありましたら、教えて頂けたらありがたいです。
よろしくお願い致します。
phpで作る掲示板でupdateを行いたい
phpで掲示板を作っています。
indexページの投稿から、更新ボタンを押して更新ページにいき更新をしようとしています。
しかし、更新ボタンを押しても該当のIDに飛ばずに更新ができません。。。
問題箇所はupdateの
SQL文を実行する準備
値のバインド
プリペアドステートメントの実行
データの取得
辺りだと思うのですが、なかなか解決しません。
ご教示の程よろしくお願いします。
該当のソースコード
index
1 echo('<p>id:'.$id.'</p>'); 2 echo('<p>投稿者:'.$name.'</p>'); 3 echo('<p>内容:</p>'); 4 echo('<p>'.$post.'</p>'); 5 echo('<form action="update2.html" method="post">'); 6 echo('<input type="submit" value="変更する">'); 7 echo('<input type="hidden" name="id" value='.$id.'>'); 8 echo('</form>'); 9 echo('<form action="delete.html" method="post">'); 10 echo('<input type="submit" value="削除する">'); 11 echo('<input type="hidden" name="id" value='.$id.'>'); 12 echo('</form>');
update
1<?php 2 3header("Content-type: text/html; charset=utf-8"); 4 5require_once("db_connect.php"); 6$dbh = db_connect(); 7 8if(empty($_POST)) { 9 echo "<a href='index.html'>index.html</a>←こちらのページからどうぞ"; 10 exit(); 11} 12 13//プリペアドステートメント 14$statement = $dbh->prepare("SELECT (id,name,post) FROM forum WHERE id = ?"); 15//プレースホルダへ実際の値を設定する 16$statement->bindValue(':id', $id, PDO::PARAM_STR); 17$statement->bindValue(':name', $name, PDO::PARAM_STR); 18$statement->bindValue(':post', $post, PDO::PARAM_STR); 19//クエリ実行 20$statement->execute(); 21/* バインドする */ 22$row = $statement->fetch(); 23?> 24 25<!DOCTYPE html> 26<html> 27<head> 28<title>変更画面</title> 29</head> 30<body> 31<h1>変更画面</h1> 32 33 <?php 34 35 $id = $row['id']; 36 $name = $row['name']; 37 $post = $row['post']; 38 $post = nl2br($post); 39 40 echo('<p>変更して下さい。</p>'); 41 echo('<form action="update3.html" method="post">'); 42 echo('名前を入力:<input type="text" name="name" value='.$name.'><br><br>'); 43 echo('<textarea name="post" rows="8" cols="40">'); 44 echo($post); 45 echo('</textarea><br><br>'); 46 echo('<input type="hidden" name="id" value='.$id.'>'); 47 echo('<input type="submit" value="変更する">'); 48 echo('</form>'); 49 50 ?> 51 52</body> 53</html> 54
.htmlでphpが扱えるように設定されているのでしたらその部分は補足で記載しておいてください。
あと、サーバーの種類やバージョン、phpのバージョン
DB定義など