nutella100
nutella100

Reputation: 75

How to pass a hidden parameter back to the form action

I am working on a restaurant search and review project. I have a search page that will show restaurant names and provides a link for the user to add a review for each restaurant result by using the hidden input rid.

In my review.php, I am using the value sent in for the hidden input rid to run another simple query and then display the name of the restaurant. Then I have several inputs so the user can input their name, their rating of the restaurant, and finally a comment.


<form action="comment.php" method="GET">
  <INPUT TYPE="hidden" NAME="rid" VALUE="">
  <?php
        $db=mysqli_connect(//parameters);

        $restaurant_id= $_GET['rid'];

        if (!empty($_GET)){
            $result = $db->query(//query);

            $row = $restaurant_result->fetch_assoc() 
            echo $row["name"];
        }
  ?>


  <INPUT //other inputs for the user>

</form>

My problem is that when the user hits a submit button at the bottom, the page will refresh with the url www..../review.php?rid= meaning that the name of the restaurant can't be displayed since no restaurant id parameter is being resent in the form. How can I send the restaurant id back to the page again once it is done?

I tried the top answer in this thread but I get the same url problem: Pass parameter to form action in HTML

Upvotes: 0

Views: 988

Answers (1)

Timothy Alexis Vass
Timothy Alexis Vass

Reputation: 2705

<INPUT TYPE="hidden" NAME="rid" VALUE="<?php if(isset($_GET['rid'])){echo $_GET['rid'];} ?>">

Upvotes: 1

Related Questions