Page 1 of 1

A problem with the switch statement

Posted: Sat Feb 28, 2009 1:53 pm
by diG1tY
Hello. I am reading the book PHP and MySQL Web Development and I am doing the exercise with the switch statement. I have copied the text, double-checked it and still I get mistakes. Here is the code:

Code: Select all

 
             switch($find)
         {
             case:'a' :
                 echo '<p>Regular customer</p>';
                 break;
             case:'b' :
                 echo '<p>tv</p>';
                 break;
             case:'c' :
                 echo '<p>i-net</p>';
                 break;
             case:'d' :
                 echo '<p>word of mouth</p>';
                 break;
             default:
                 echo 'Why don\'t know';
                 break;
         }
The $find variable takes data from an select tag with possible values :a,b,c,d. I am using netbeans and it says:
Syntax error:
expected: exit,if...and so on.
What am I doing wrong ?

Re: A problem with the switch statement

Posted: Sat Feb 28, 2009 2:20 pm
by greyhoundcode
diG1tY wrote:

Code: Select all

case:'a' :
    echo '<p>Regular customer</p>';
    break;
You have some extra colons in there. Instead of

Code: Select all

case:'a':
just write

Code: Select all

case 'a':

Re: A problem with the switch statement

Posted: Sat Feb 28, 2009 2:23 pm
by diG1tY
:cry: I curse my poor eyesight -_-