SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Philippines
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    HELP... Global declaration.

    Hi,

    In my header.inc template, I declared:

    <?php
    global $INDEXTYPE;
    ?>

    in my Registration form, I passed a value to my global variable:

    <?php
    $page_title = 'Welcome!';
    include ('./header.inc');
    $GLOBALS("INDEXTYPE")="AA";
    ?>

    I got this error:

    parse error, unexpected '=' in C:\web\Apds\Registration_form.php on line 6

    This is line 6:
    $GLOBALS("INDEXTYPE")="AA";


    What is wrong with my code?

    jozin

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Örebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    You only have to declare a variable as global when you are inside of a function.

    PHP Code:
    <?php
    $page_title 
    'Welcome!';
    include (
    './header.inc');
    $INDEXTYPE "AA";
    ?>
    If you want to access it in header.inc, do like this:

    PHP Code:
    Registration_form.php

    <?php
    $page_title 
    'Welcome!';
    $INDEXTYPE "AA";
    include (
    './header.inc');
    ?>

    header.inc

    <?php
    echo $INDEXTYPE;
    ?>
    Yours, Erik.

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Philippines
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks for the info

    Hi Erik,

    Thanks for the info. I want to test the value of value of INDEXTYPE in my Process.php script.

    <?php
    if $INDEXTYPE=="AA")
    {
    Do something…
    }
    elseif $INDEXTYPE=="BB")
    {
    Do something…
    }
    ?>

    is this OK?

    or should i use
    if ($_GET['INDEXTYPE']=="AA")...

    jozin

  4. #4
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Örebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    You can use the first method if you include Process.php in Registration_form.php after you have defined $INDEXTYPE.

    Yours, Erik.


Bookmarks

Posting Permissions

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