dongyuan9892 2016-11-12 12:14
浏览 49
已采纳

通过GET获取参数并通过POST(PHP)提交

I have got an issue to ask related with GET/POST.

I am trying to make a simple blog with posts and comments of them.

From each post I have got on main page, I would like to add a comment form in a new page that enables to save the post´s index to have a control of the commentaries.

I get this index value through GET in the new page but when I submit the form via POST I lose the reference to the index.

I read that is not possible to use both methods at the same time and I would like to know how can I keep a parameter from the main page and store it with the rest of the values in the new form.

Thanks a lot,

BR

http://localhost/simple_blog_new_comment.php?postIndex=xx

<form action='simple_blog_new_comment.php' method='POST'> 
        Commentary:<br> 
        <textarea onfocus='clearContent(this)' cols='30' rows='5' name="txt_comment">Enter the text here...</textarea><br> 
        Author: <input type='text' name='txt_comment_author'><br> 
        <input type='submit' name='btn_comment_submit'><br><br>
    </form>

</div>
  • 写回答

2条回答 默认 最新

  • dongzanghong4379 2016-11-14 19:37
    关注

    I found a solution for this problem I would like to share in case someone have the same trouble.

    Finally I get working my "Posts" and "Comments" databases fixing the variable reference problem using $_SESSION superglobal variable.

    It works like this:

    session_start(); // This allows the use of $_SESSION superglobal var
    
    $_SESSION['index'] = $_GET['postIndex']; // Save the variable into $_SESSION
    

    With this superglobal variable you can keep the index variable as a cookie for using it as long as you keep the session opened.

    More related info here: http://php.net/manual/es/reserved.variables.session.php

    Thanks again! :D

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化