How to remember $_POST value when change the URL?

Discussion in 'Web Design and Development' started by youlichika, Sep 24, 2010.

  1. youlichika macrumors member

    Joined:
    Aug 27, 2010
    #1
    I have got two page.

    page a.php
    HTML:
    <form action="b.php" method="post">
    <input id="a1" type="text" value="keyword" name="a1" />
    <input type="submit" value="post"/>
    </form>
    page b.php
    HTML:
    <a href="b.php?id=".$row["url"]."" target="_self" >".$row["title"]."'.$_POST["a1"].'</a>
    <li>".$row["name"]."'.$_GET["id"].'</li>
    $row["url"],$row["title"] and $row["name"] are all query from mysql.
    After b.php received the $_POST value from a.php, it combined to a new hyperlink with $row["title"]. When click this hyperlink, the new value with ".$row["name"]." in <UL> <LI>.

    Now when the url change to b.php?id=".$row["url"].", the $_POST value from a.php lost. How to deal with this problem? Thanks.
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
  3. Angelo95210 macrumors 6502a

    Angelo95210

    Joined:
    Jan 7, 2009
    Location:
    Paris, France
    #3
    Yep, I confirm. A session is what you need.

    Code:
    $_SESSION['xxx'] = $_POST['xxx']
    ps you have to open your session first...
     
  4. youlichika thread starter macrumors member

    Joined:
    Aug 27, 2010
    #4
    I try to use

    Code:
    session_start();
    if($_SERVER['REQUEST_METHOD']=="POST") {
      $_COOKIE["key"] = $_POST["key"] ;
    }
    ?>
    
    or
    
    session_start();
    if($_SERVER['REQUEST_METHOD']=="POST") {
      $_SESSION["key"] = $_POST["key"] ;
    }
    ?>
    but it is failed.
     
  5. Darth.Titan macrumors 68030

    Darth.Titan

    Joined:
    Oct 31, 2007
    Location:
    Austin, TX
    #5
    Or you could pass the $_POST value along in the URL also.
    PHP:
    <a href="b.php?id=".$row["url"]."&a1=".$_POST["a1"]."\" target="_self" >".$row["title"]."'.$_POST["a1"].'</a>
    <li>"
    .$row["name"]."'.$_GET["id"].'</li>
    Then "a1" will be available as $_GET['a1']
     
  6. HomeBru Studios macrumors member

    HomeBru Studios

    Joined:
    Jun 4, 2008
    #6

    Instead of testing the request method why not do this:
    Code:
    if(isset($_POST["key"])) {
        $_SESSION["key"] = $_POST["key"] ;
    }
     
  7. youlichika thread starter macrumors member

    Joined:
    Aug 27, 2010
    #7
    Great, thanks to all. Under your halp, I have solved the problem.
    Shake hands ;)
     

Share This Page