Trouble with $_GET (probably just a stupid mistake)

Discussion in 'PHP' started by Tony Brar, Jun 10, 2012.

  1. #1
    Hi guys!

    My problem is with the file upload.php. For it to work, you have to give it the $_GET value content_type. So you have to go to upload.php?content_type=game.(or video or song)
    I have some code that should display the correct logo. However, all it does is display the music logo (even when $_GET['content_type'] should = game or video instead of song).
    Here is the code:
    
    <?php
    //return logo
    if ($_GET["content_type"]="song")   {   // code to display music logo   }
    elseif ($_GET["content_type"]="game")   {   // code to display games logo   }
    else   {   //code to display videos logo   }?>
    
    PHP:
    Can someone tell me how to make this work?
     
    Solved! View solution.
    Last edited: Jun 10, 2012
    Tony Brar, Jun 10, 2012 IP
  2. #2
    You need == otherwise you are asigning the value to the variable.

    
    <?php
    //return logo
    if ($_GET["content_type"]=="song")   {   // code to display music logo   }
    elseif ($_GET["content_type"]=="game")   {   // code to display games logo   }
    else   {   //code to display videos logo   }?>
    
    PHP:
     
    sarahk, Jun 10, 2012 IP
  3. Tony Brar

    Tony Brar Active Member

    Messages:
    220
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    75
    #3
    Thanks, that solved the problem. I gave best answer.

    - Tony
     
    Tony Brar, Jun 11, 2012 IP
  4. DaySeven

    DaySeven Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    2
    Trophy Points:
    0
    #4
    If you are going to be processing several different options, why not use the switch statement? I find that for my efforts, when the code for each option is small and very similar this is a better way to go. It seems, to me anyway, easier to add/remove items to the list.

    
    switch ($_GET['content_type']) {
      case 'song':
        $_logo = 'song_logo.png';
        break;
      case 'game':
        $_logo = 'game_logo.png';
        break;
      case '...':
        $_logo = '..._logo.png';
        break;
      default:
        $_logo = 'default_logo.png';
    }
    
    // display $_logo
    
    Code (markup):
    Just an option, of course
     
    DaySeven, Jun 11, 2012 IP
  5. Tony Brar

    Tony Brar Active Member

    Messages:
    220
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    75
    #5
    oh, so that's how to use switch. thanks!
     
    Tony Brar, Jun 12, 2012 IP