Problem retaining value with GET statement

Discussion in 'PHP' started by jzieba01, Jul 4, 2009.

  1. #1
    I have a webpage with a php script. At the beginning of the script, I set the value of the message variable with the following.

    $message = $_GET['msg3'];

    msg3 is coming from the url. That is working fine because I am printing $message correctly on the webpage.

    The webpage has a form and the rest of the php script is run when the form is submitted. The problem is that when the form is run, $message is now empty.

    How do I get it to retain the value.

    Thanks for the help.
     
    jzieba01, Jul 4, 2009 IP
  2. zeronese

    zeronese Peon

    Messages:
    83
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    here is two ways to do that,
    1 - either store the $message variable in a session:
    Session_start();
    $_session[‘message’] = $message;
    PHP:
    Then when the form is submitted you can use:
    $message = $_session[‘message’];
    PHP:
    2- The second way would be to store the $message in a hidden field of the form and retrieve it when the form is submitted.
    <form action="" method="get">
    other form input here
    <input name="message" type="hidden" value="<?php echo $message; ?>" />
    </form>
    PHP:
    good luck :)
     
    zeronese, Jul 4, 2009 IP
  3. jzieba01

    jzieba01 Guest

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks zeronese. I used the form method and it worked great.
     
    jzieba01, Jul 4, 2009 IP
  4. zeronese

    zeronese Peon

    Messages:
    83
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    great... glad it worked.
     
    zeronese, Jul 4, 2009 IP