Switch statement undefined index error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • furqi
    New Member
    • Dec 2009
    • 21

    #1

    Switch statement undefined index error

    hi i am actually having problem in this code i am trying to check the value in the if condition in the very last lines of the code but i am facing an error of "undefined index" can anybody tell me so that i can solve my problem.


    Code:
    <html>
    <body>
    <form method="GET" action="switchcases.php">
    <input type='text' name='furqan' >
    <?php
    $NAME=$_GET['furqan'];
    switch($NAME)
    {
     case "ALLAH" :
     echo "ya ALLAH madad";
     break;
    
     case "furqan" :
     echo "hi i am furqan ahmed";
     break;
    
     case "bhaijaan" :
     echo "hello bhai jaan is speaking";
     break;
    
     default:
     if(($_GET['furqan']!="")&&(($_GET['furqan']!="ALLAH")|| this($_GET['furqan']!="furqan")||($_GET['furqan']!="bhaijaan")))
    // the above is the line where i am getting the problem
     echo "neither of the case";
    }
    ?>
    </form>
    </body>
    </html>
  • zorgi
    Recognized Expert Contributor
    • Mar 2008
    • 431

    #2
    First that line is not ending with Semicolumn ";"
    Second you don't need that line at all. Just delete it or comment it out and it will work. All that maybe you want to add is
    Code:
     case "" :
     echo "whatever you want to say here";
     break;
     
     default:
     echo "neither of the case";

    Comment

    • furqi
      New Member
      • Dec 2009
      • 21

      #3
      Actually the thing is that if i will ot enter any ting in the text box it will run the default(neither of the case) thats why i added this line so the te page should be blank

      Comment

      • zorgi
        Recognized Expert Contributor
        • Mar 2008
        • 431

        #4
        So what do you want it to say if empty string entered? You probably best to have a look at the manual : switch

        Comment

        Working...