A problem with the switch statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
diG1tY
Forum Newbie
Posts: 17
Joined: Sun Feb 01, 2009 2:50 pm

A problem with the switch statement

Post 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 ?
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Re: A problem with the switch statement

Post 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':
diG1tY
Forum Newbie
Posts: 17
Joined: Sun Feb 01, 2009 2:50 pm

Re: A problem with the switch statement

Post by diG1tY »

:cry: I curse my poor eyesight -_-
Post Reply