SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2003
    Location
    India
    Posts
    160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Notice: Undefined index

    I have a program that look like

    PHP Code:
    <?php

    if($_REQUEST['flag']=="F"){

    // Code Block Here

    } elseif($_REQUEST['flag']=="K") {

    // Code Block Here

    } elseif($_REQUEST['flag']=="L") {

    // Code Block Here

    } elseif($_REQUEST['flag']=="M") {

    // Code Block Here

    }

    ?>
    I am getting error.

    Notice: Undefined index: flag in D:\sites\view_help.php on line 74

    What is the correct way to write a code block like this ?

  2. #2
    SitePoint Zealot Dachande663's Avatar
    Join Date
    Feb 2005
    Location
    Birmingham, UK
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You want to use a switch statement like so:
    PHP Code:
    switch ($_REQUEST['flag']) {
    case 
    'F':
        
    // Code block here
        
    break;
    case 
    'K':
        
    // Code block here
        
    break;
    case 
    'L':
        
    // Code block here
        
    break;
    case 
    'M':
        
    // Code block here
        
    break;

    Web Developer & Geek: hybridlogic.co.uk ~ lukelanchester.com

  3. #3
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if (isset($_REQUEST['flag']) {

        switch (
    strtoupper($_REQUEST['flag'])) {
            
            case 
    'F':
                break;
            
            case 
    'K':
                break;
            
            case 
    'L':
                break;
            
            case 
    'M':
                break;
        
        }


    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  4. #4
    SitePoint Zealot
    Join Date
    Jun 2003
    Location
    India
    Posts
    160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the suggestions, i will try that.


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
  •