variable value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tuananh87vn
    New Member
    • Sep 2007
    • 63

    #1

    variable value

    hello, I need some help!

    in this first page I have a variable $v1 which hold some value. without post method, cookie or session, is there any other way to keep the value when we submit a form and move to another page. the problem is that this $value does not belong to the form so I don't know how to keep its value when moving to other pages.
  • Lumpy
    New Member
    • Oct 2007
    • 69

    #2
    I have two different ideas, maybe one of them will work

    First, if the data isn't something like a password, can you just pass it through in the link to the page that handles the form.
    [CODE=php]
    echo "<form method=\"post\" action=\"page.p hp?var=" . $v1 . "\">";
    [/CODE]

    Second, use a hidden input in your form and assign that the value you need to pass to the next page with the form.

    [CODE=php]
    echo "<input type=\"hidden\" name=\"var\" value=\"" . $v1 . "\">";
    [/CODE]

    With the second way, even though the value doesn't belong to the form, you can still use the form to pass the variable.

    Comment

    • nathj
      Recognized Expert Contributor
      • May 2007
      • 937

      #3
      Originally posted by tuananh87vn
      hello, I need some help!

      in this first page I have a variable $v1 which hold some value. without post method, cookie or session, is there any other way to keep the value when we submit a form and move to another page. the problem is that this $value does not belong to the form so I don't know how to keep its value when moving to other pages.
      Hi,

      Is there any reason why you can't use sessions? I have done just this, passing data on through multiple forms and Sessions is defeiniltey the easiest way to do it.

      Alternatively the suggestions about loading it to a hidden input will enable you then to POST the data across, but if there's lots of data this gets a bit messy in code. Sessions are the obvious solution to this problem

      Cheers
      nathj

      Comment

      Working...