Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
257 views
in Technique[技术] by (71.8m points)

php - 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

question from:https://stackoverflow.com/questions/65880611/how-to-pass-a-hidden-parameter-back-to-the-form-action

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...