【phpの勉強】
【phpの勉強】
http://rara.mods.jp/php/0821_index
http://rara.mods.jp/php/search.html
【index.html】
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <title>お問い合わせ入力フォーム</title> <link href="style.css" rel="stylesheet" media="screen, print"> </head> <body> <form action="check3.php" method="post" id="inquiry"> <table summary="お問い合わせに関する入力項目名とその入力欄"> <tr> <th><label for="name">お名前</label></th> <td><input type="text" name="name" size="30" id="name" class="text1"></td> </tr> <tr> <th><label for="email">メールアドレス</label></th> <td><input type="text" name="email" size="30" id="email" class="text2"></td> </tr> <tr> <th><label for="message">ご意見</label></th> <td><textarea name="message" cols="30" rows="5" class="text3" id="message"></textarea></td> </tr> </table> <input type="submit" value="確認画面へ"> </form> </body> </html>
【search.html】
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <title>検索</title> <link href="style.css" rel="stylesheet" media="screen, print"> </head> <body> <form action="search.php" method="post" id="search"> code:<input type="text" name="code" size="20" id="code"> name:<input type="text" name="name" size="20" id="name"> <br> <input type="submit" value="検索" /> </form> <ul> <li><a href="menu.html">メニューに戻る</a></li> </ul> </body> </html>
【search.php】
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <title>検索画面</title> <link href="style.css" rel="stylesheet" media="screen, print"> </head> <body> <?php $code = $_POST['code']; $name=$_POST['name']; $dsn = 'mysql:dbname=xxxx;host=xxxx'; $user = 'xxxx'; $password = 'xxxx'; $dbh = new PDO($dsn, $user, $password); $dbh -> query('SET NAMES UTF8'); $sql = 'SELECT * FROM inquiry WHERE code=? OR name=?'; $stmt = $dbh -> prepare($sql); $data[] = $code; $data[] = $name; $stmt -> execute($data); while(1) { $rec = $stmt -> fetch(PDO::FETCH_ASSOC); if($rec == false) { break; } echo $rec['code'].': '; echo $rec['name'].': '; echo $rec['email'].': '; echo $rec['message']; echo '<br>'; } $dbh = null; ?> <ul> <li><a href="search.html">検索画面に戻る</a></li> </ul> </body> </html>