>我有一个页面,我在其中获取 ques ID 并将其插入我正在做的数据库中
网址: */FAQ/faq_question_sol.php?ques= 62*
这($selected_ques= ($_GET['ques']);
)在*faq_question_sol.php*中工作正常,但*answer_submit_process.php*无法识别它我的表格
<form id="post-form" class="post-form" method="POST" action="answerswer_submit_process.php">
<input id="submit-button" type="submit" tabindex="120" name="submitbutton" value="Post Your Answer" />
</form>
*answer_submit_process.php* 是
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);
}
最快的解决方案是在表单的隐藏字段中保存 $_GET['ques'] 的值,从而使其在answer_submit_process.php中可访问。
像这样:
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']..
如果您通过表单 POST 发送,那么您可以从中获取数据的变量是 $_POST 而不是 $_GET。无论如何,我无法在您的表单上找到与 ques 变量相关的任何字段,它们在哪里?
将<input type="hidden" name="ques" value="<?php echo $_GET['ques'] ?>"/>
添加到窗体中以临时存储变量,然后使用变量$_POST['ques']
代替处理页中的$_GET['ques']
。
或者,您可以将表单操作更改为 answer_submit_process.php?ques=<?php echo $_GET['ques']; ?>
。