Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2003
    Location
    Belgium
    Posts
    23

    Talking Unanswered: passing variables

    Hi,

    Can anyone tell me how to pass variables between all your html pages ?

    The situation :

    I have a login page, if I submit I come in my menu-page and there are 2 variables coming with it :
    $statusCheck and $companyCheck.

    But now I have to go to a new page from the menu-page, and I still need my variables $statusCheck and $companyCheck. How can I pass them through without using a form ?

    Thanks.
    You help me, and I'll try to help you

  2. #2
    Join Date
    Oct 2002
    Location
    Plymouth UK
    Posts
    116
    Pass them using sessions. You will need to start the session and register the variables.

    Code:
    session_start();
    session_register("variable_name");
    Read up about sessions and session variables.

  3. #3
    Join Date
    Apr 2003
    Location
    Belgium
    Posts
    23
    Yes, but it's already in my login page, if I have to go to several pages, do I have to put it every time in a session again ?

    $companyCheck from the login page to the menu page.
    $companyCheck from the menu-page to my license-page

    Like :

    Login.php :

    Code:
    session_start();
    session_register("companyCheck");
    menu.php :

    I can use $companyCheck without opening a session or without using HTTP_GET_VARS or something.

    If I now want to use $companyCheck in my license-page, do I have to put a session in my menu-page ?

    license.php :

    I want to use $companyCheck in a recordset. Do I have to use a special feature here for that ? like
    Code:
    $companyCheck=HTTP_GET_VARS['companyCheck']
    Thanks for the help, because I'm reading about it in "MySQL/PHP Database Applications by Jay Greenspan and Brad Bulger", but the chapter sessions and variables aren't so clear for me.
    You help me, and I'll try to help you

  4. #4
    Join Date
    Oct 2002
    Location
    Plymouth UK
    Posts
    116
    Very briefly the sessions work is like the following code:

    First page (test1.php)

    Code:
    <?php
    session_start();
    session_register("test_var");
    
    $test_var = "Should be able to read this";
    ?>
    <a href="test2.php">Click here...</a>
    Second page (test2.php)
    Code:
    <?php
    session_start();
    echo ($test_var);
    ?>
    When you click the link the text in the variable should appear on the page.

  5. #5
    Join Date
    Apr 2003
    Location
    Belgium
    Posts
    23

    Smile

    Ok, thanks for the help.
    You help me, and I'll try to help you

  6. #6
    Join Date
    Apr 2003
    Location
    Belgium
    Posts
    23
    Thanks for the help allready, but I still have a question.
    Everything works fine like you said, but I can't use the variable in a query.
    I want to make a list for showing all the licenses from the company where the user who logged in belongs to.

    So I made a recordset (query) and a dynamic table in dreamweaver, and it gave me the following code:

    Code:
    <?php require_once('../../Connections/fisherintranet.php'); ?>
    <?php
    session_start();
    $colname_licenties = "1";
    if (isset($HTTP_SESSION_VARS['$companyCheck'])) {
      $colname_licenties = (get_magic_quotes_gpc()) ? $HTTP_SESSION_VARS['$companyCheck'] : addslashes($HTTP_SESSION_VARS['$companyCheck']);
    }
    mysql_select_db($database_fisherintranet, $fisherintranet);
    $query_licenties = sprintf("SELECT license FROM licenties WHERE company = '%s' ORDER BY license ASC", $colname_licenties);
    $licenties = mysql_query($query_licenties, $fisherintranet) or die(mysql_error());
    $row_licenties = mysql_fetch_assoc($licenties);
    $totalRows_licenties = mysql_num_rows($licenties);
    ?>
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <?php echo $companyCheck; ?>
    <p>&nbsp;</p>
    
    <p>&nbsp;</p>
    
    
    <table border="1" cellpadding="0" cellspacing="0">
      <tr> 
        <td>license</td>
      </tr>
      <?php do { ?>
      <tr> 
        <td><?php echo $row_licenties['license']; ?></td>
      </tr>
      <?php } while ($row_licenties = mysql_fetch_assoc($licenties)); ?>
    </table>
    </body>
    </html>
    <?php
    mysql_free_result($licenties);
    ?>

    Can you see what's wrong ? Because when I check it out, it displays the correct variable (<?php echo $companyCheck; ?>), but it doesn't show the list of licenses.

    Thanks again for your help.
    You help me, and I'll try to help you

  7. #7
    Join Date
    Oct 2002
    Location
    Plymouth UK
    Posts
    116
    To access variables from the session vars you need to drop the $ symbol.

    So that the code is:
    Code:
    ....$HTTP_SESSION_VARS['companyCheck']...
    Otherwise you will be searching the HTTP_SESSION_VARS array for a variable with the name set in the value of the companyCheck. If $companyCheck = "XYZ" you would look the HTTP_SESSION_VARS for the variable named "XYZ" whereas you need "companyCheck".

  8. #8
    Join Date
    Apr 2003
    Location
    Belgium
    Posts
    23
    Thanks !!! That's the solution for my problem.
    Great that you can ask help as a newbie here.
    You help me, and I'll try to help you

  9. #9
    Join Date
    Oct 2002
    Location
    Plymouth UK
    Posts
    116
    No problem. Happy I could help solve your problem.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •