phpとmysqlで①入力フォーム(form.php)、②入力確認フォーム(confirm.php)、③完了画面(submit.php)の3つのページを使って完了するログイン機能付きの予約サイトを作っています。
②の確認画面(confirm.php)でpreg_matchを使って入力をを許可しデータベースへ入れるもしくははじくを選別したいのですが、現状form.phpで送信するとconfirm.phpが真っ白になってしまいます。
confrim.phpでpreg_matchのif文を追加するまでは動作していたので、そこが原因だと思うのですが、原因がわかりません。
ご指摘していただけると助かります。
宜しくお願い致します。
*データベースに接続確認済み
入力したい文字
大小数字、日本語、大小アルファベット、空欄、改行、。
拒否したい文字の例
<a href="">URL</a>
https://teratail.com/questionsのようなURL
javascript文
form.php var_dump($shop_result['shop_id']); //->数字 <form action="confirm.php?shop_id=<?=htmlspecialchars( $shop_result['shop_id'], ENT_QUOTES, 'UTF-8');?>" method="post"> <div class="form-group"> <label for="InputReserveComment" >コメント</label><br> <textarea col="10" rows="2" name="comment" class="form-control" placeholder="予約条件など"></textarea><br><br> </div> <input id="send" name="reserve" type="submit" value="送信" > </form>
confirm.php <?php if (preg_match("/\A[a-zA-Z0-90-9ぁ-んァ-ヶー一-龠、。\n\r]\z/mu",$_POST['comment'])|| ($_POST['comment'] == null)){ $_SESSION['comment'] = $_POST['comment']; exit; } else { header('Location: error.php'); } ?> <!DOCTYPE HTML> <html lang="ja"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title></title> </head> <body> <form action="reserve_submit.php?shop_id=<?=htmlspecialchars($shop_result['shop_id']);?>" method="post" > <table > <tr><th > 店舗名: </th><td ><?=htmlspecialchars( $shop_result['shop_name'],ENT_QUOTES,'utf-8');?></td></tr> <tr><th>コメント:</th><td><?php echo htmlspecialchars($_SESSION['comment'] ,ENT_QUOTES,'utf-8') ?></td></tr> </table> <input id="send" name="reserve" type="submit" value="登録する"> </form> </body> </html>
submit.php $comment = $_SESSION['comment']; // データの追加 $sql = "INSERT INTO reserve(reserve_shop_id,reserve_comment,reserve_tel) VALUES(?,?,?)"; $stmt = $pdo -> prepare($sql); $stmt -> execute([$shop_id,$comment,$tel]);
回答2件
あなたの回答
tips
プレビュー