Home>

■ Problems
When I post a review, it becomes the following url and the screen becomes blank.

Before posting a review
http: // localhost: 8888/public/detail.php? id = 1
After posting a review
http: // localhost: 8888/public/detail.php? add_review = aaaaaa

<? php
ob_start ();
session_start ();
?>
<? php
// Post a review
if ($_POST ['add_review']) {
    $add_review = $_POST ['add_review'];
    add_review ($product_id, $add_review, $mysqli);
}
 ?>

    
         
              Post a review 
          <form>
              <textarea name = "add_review" placeholder = "Please write a review."></textarea>
              <button type = "submit">submit</button>
          </form>
         
    
function add_review ($product_id, $add_review, $mysqli) {
    $product_id = $mysqli->real_escape_string ($product_id);
    $add_review = $mysqli->real_escape_string ($add_review);
    $user_id = $_SESSION ['user'];
    $query = "INSERT INTO
                    reviews (
                        review_comment,
                        review_date,
                        review_product_id,
                        review_user_id
                    )
                    VALUES (
                        '$add_review',
                        NOW (),
                        $product_id,
                        $user_id
                    ) ";
    $result = $mysqli->query ($query);
    if (! $result) {
        echo'An error has occurred. ';
    } else {
        echo'Posted a review';
    }
}
?>
  • Answer # 1

    Specify action and method in form tag
    If you want to display it in detail.php even after posting a review, you may not need to specify action.

    <form action = "detail.php" method = "GET">