Need Help, With strange thing in [SWITCH] code

Discussion in 'PHP' started by Ma3FooS, Aug 30, 2007.

  1. #1
    Dear All

    I have one strange issue in the switch code

    Fist I have two PCs with AppServ and two web sites each one of them in different company

    now

    I created one page called test.php
    and I put in side it a simple switch code from php.net
    <?php
    switch ($i) {
    case "apple":
        echo "i is apple";
        break;
    case "bar":
        echo "i is bar";
        break;
    case "cake":
        echo "i is cake";
        break;
    }
    ?> 
    PHP:
    i copyed the page to my 2 PCs and the web sites

    when I run the page
    .../test.php?i=apple

    one of the PC its working fine I can see the out put [i is bar] but in the ather PC i can't.
    also one of the web sites its working and in the other its not
    all of them are using PHP5+



    Strange right

    ---------
    notes that i wrote ones
    <?php
    
    
    echo $;
    
    
    switch ($i) {
    case "apple":
        echo "i is apple";
        break;
    case "bar":
        echo "i is bar";
        break;
    case "cake":
        echo "i is cake";
        break;
    }
    ?> 
    PHP:
    .../test.php?i=apple


    and there is no output


    please help

     
    Ma3FooS, Aug 30, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    It's a register_globals issue. Replace the $i in the switch() with $_GET['i'] and it'll work.
     
    nico_swd, Aug 30, 2007 IP
  3. Ma3FooS

    Ma3FooS Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    also

    I made one case as its null
    case "":
        echo "i is null";
        break;
    PHP:
    and win i run the page
    .../test.php?i=apple

    but its print the null case...
    so the $i didn't take the apple


    why
     
    Ma3FooS, Aug 30, 2007 IP
  4. Ma3FooS

    Ma3FooS Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    ok I will try


    thanks nico
     
    Ma3FooS, Aug 30, 2007 IP
  5. Ma3FooS

    Ma3FooS Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    oh

    nice

    thanks man


    now its working
     
    Ma3FooS, Aug 30, 2007 IP