简体   繁体   中英

How to get url id from another page by form action page

i have a page where i am getting the ques id and insert it in the database for that i am doing

url: */faq/faq_question_sol.php?ques= 62*

this ( $selected_ques= ($_GET['ques']); ) is working properly in the *faq_question_sol.php* but the *answer_submit_process.php* does not recognize it my form

 <form id="post-form" class="post-form" method="POST" action="answer_submit_process.php">
    <input id="submit-button" type="submit" tabindex="120" name="submitbutton" value="Post Your Answer" />

 </form> 

and the *answer_submit_process.php* is

if(isset($_POST['submitbutton'])){
$userid = $_SESSION['userid']; // i have already started the session
 $selected_ques=  ($_GET['ques']);  
$content =  $_POST["content"] ;

$query="INSERT INTO `formanswer`( `user_id`,`questionid`,`content` )  VALUES ('{$userid}','{$selected_ques}','{$my_html}' ) ";
     $result=mysql_query($query);
  }

Quickest solution would be saving the value of $_GET['ques'] on a hidden field of the form and thus make it accessible in answer_submit_process.php.

Something like this:

 if (isset($_GET['ques'])){
      echo '<input type="hidden" name="ques" value="'.$_GET['ques'].'">';
 }

And in answer_submit_process page the value could easily accessed by $_POST['ques']..

If you are sending via a form POST, then the variable from which you can get data is $_POST instead of $_GET. Anyway, i wasn´t able to find any field relating to the ques variable on your form, where are they?

Add <input type="hidden" name="ques" value="<?php echo $_GET['ques'] ?>"/> to your form to temporarily store the variable, and then use the variable $_POST['ques'] in place of $_GET['ques'] in the processing page.

Alternatively, you could change the form action to answer_submit_process.php?ques=<?php echo $_GET['ques']; ?> answer_submit_process.php?ques=<?php echo $_GET['ques']; ?> .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM