basic question about $variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Japhy

    basic question about $variable

    Hello,
    I am writing my first website using PHP/MYsql.
    I bought some PHP templates to help (from SoftVelocity).
    Basically, so far, my application first pulls up a table of key values
    from the DB. This 'key' value is basically a component of the key for
    each of the 'child' tables.
    I click on one of the parent keys in the table and save it's value in
    $my_contnum, and move to a page that has a form for entering in a
    'child' key value. Some how, $my_contnum gets 'zeroed out'.
    When I post to add the child key to its table, the value for
    $my_contnum is 0.
    My question : shouldn't a $variable to good for the whole session,
    across pages.
    There is a lot of extraneous code generated by the template, and I may
    be missing something, but I can't see where it is being reset.
    TIA for any ideas or suggestions!
    J

  • ZeldorBlat

    #2
    Re: basic question about $variable

    Variables only exist for the duration of script execution. If you set
    a variable, it will exist until the script finishes. If you want to
    have variables available from page to page, you either need to send it
    along as an HTTP (GET or POST) variable, or store it in a session. I'm
    not sure what your examples look like, but you can read all about
    sessions here:



    If you wanted to use an HTTP (GET) variable, the easiest way would be
    to create a link on the first page that looked something like:

    http://www.mysite.com/page2.php?my_co ntnum=$my_contn um

    When the user clicks on that link (on page1.php) the variable will be
    passed along. On the second page, you can get to it by using
    $_GET['my_contnum'].

    Comment

    • Japhy

      #3
      Re: basic question about $variable

      Thanks, that was exactly what I was looking for.
      I thought every $ variable acted as a session variable.
      Believe me, I do research this stuff before I post...I'm
      just a little overwhelmed right now...your help is greatly
      appreciated!

      Comment

      Working...