###前提・実現したいこと
PHPで投稿機能のある掲示板を作りたいです。
エラーメッセージの内容で問題が起きており、クチコミを投稿できない状態です。
初心者でしてコピペとググりながら対応していますが、どのように修正したらいいのかが分かりません。
ご教授いただけますと幸いです。
###発生している問題・エラーメッセージ
[error] [client *************] PHP Notice: Undefined variable: review_comment2 in /var/www/html/dev.example/product.php on line 144, referer: http://dev.example.com/product.php?id=2 [error] [client *************] PHP Notice: Undefined variable: add_review in /var/www/html/dev.example/app/functions/review.php on line 55, referer: http://dev.example.com/product.php?id=2
###該当のソースコード
PHP
1 2// 口コミを投稿する 3function add_review($product_id, $review_points, $review_comment1, $review_comment2, $mysqli) { 4 $product_id = $mysqli->real_escape_string($product_id); 5 $add_review = $mysqli->real_escape_string($add_review); 6 $user_id = $_SESSION['user']; 7 8 $query = "INSERT INTO 9 reviews( 10 review_points, 11 review_comment1, 12 review_comment2, 13 review_date, 14 review_product_id, 15 review_user_id 16 ) 17 VALUES ( 18 '$review_points', 19 '$review_comment1', 20 '$review_comment2', 21 NOW(), 22 $product_id, 23 $user_id 24 )"; 25 26 $result = $mysqli->query($query); 27 28 if(!$result) { 29 echo 'エラーが発生しました。'; 30 } else { 31 echo "口コミを投稿しました。"; 32 } 33} 34 35--------------- 36 37<?php 38// 口コミの投稿 39if ($_POST) { 40 // 必須項目に情報が入っているかを確認する 41 if ( !empty( $_POST['add_review'] )) { 42 $add_review = $_POST['add_review']; 43 add_review($product_id, $review_points, $review_comment1, 44 $review_comment2, $mysqli); 45 } else { 46 echo "口コミを入力してください"; 47 } 48} 49 ?> 50<!-- 口コミをするボタン --> 51<p><a data-open="exampleModal2" href="#features" class="button">クチコミする</a></p> 52<!-- This is the first modal --> 53<div class="reveal" id="exampleModal2" data-reveal> 54 <h5>投稿フォーム</h5> 55 <button class="close-button" data-close aria-label="Close reveal" type="button"> 56 <span aria-hidden="true">×</span> 57 </button> 58<form action="" method="post"> 59 <label for="review_points">この商品を評価してください。</label> 60 <input type="radio" class="form-control" id="review_points" name="add_review" value="1">1 61 <input type="radio" class="form-control" id="review_points" name="add_review" value="2">2 62 <input type="radio" class="form-control" id="review_points" name="add_review" value="3">3 63 <input type="radio" class="form-control" id="review_points" name="add_review" value="4">4 64 <input type="radio" class="form-control" id="review_points" name="add_review" value="5">5 65 <br> 66 <label for="review_comment1">[良かった点]</label> 67 <textarea name="add_review" class="form-control" placeholder="クチコミを記入してください。"></textarea> 68 <label for="review_comment2">[悪かった点]</label> 69 <textarea name="add_review" class="form-control" placeholder="クチコミを記入してください。"></textarea> 70 <hr> 71 <button type="submit" class="button" data-open="exampleModal3">投稿する</button> 72</form> 73 74</div> 75 76<!-- This is the nested modal --> 77<div class="reveal" id="exampleModal3" data-reveal> 78 <h5>投稿ありがとうございます。</h5> 79 <button class="close-button" data-close aria-label="Close reveal" type="button"> 80 <span aria-hidden="true">×</span> 81 </button> 82</div>
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報
PHP5.6 MySQL5.6