FRIHOSTFORUMSSEARCHFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

need some help - php switch code

 


billybob
hi can anybody help me with this code please

switch ($department)
{
case 1
$email = 'xxx@xxxxxx.co.uk';
break;
case 2
$email = 'xxx@xxxxxx.co.uk';
break;
case 3
$email = 'xxx@xxxxxx.co.uk';
break;
case 4
$email = 'xxx@xxxxxx.co.uk';
break;
case 5
$email = 'xxx@xxxxxx.co.uk';
break;
}

...html code in between

<?
$department = array(
1 => "Web Design (Ryan Norton)",
2 => "Multimedia (Joe Groves)",
3 => "Photography (Oliver Brayford)",
4 => "Scripting (Andrew Siddle)",
5 => "Logo Design (Andrew Figg)",
);
$department = str_replace(" ", " ", $department);

echo '<select name=department>';
foreach($department as $key => $value)
{
echo '<option value='.$value.'> '.$value.'';
}
echo '</select>';
?>

this is ment to be a dropdown list and displays the names which i got working (the second section) then the code to set the email address(the first section) but when i run the code i get the error

Parse error: parse error, unexpected T_VARIABLE in /home/asiddle4/public_html/contactform.php on line 158

which is this line

157 case 1
158 $email = 'xxx@xxxxxx.co.uk';
159 break;

can anyone help me please

thanks
Marston
All I know is that you need a default statement in your switch statement...
BlackSkad
You need to type a colon after the words case '1'. A valid case-block looks like below:
Code:
case 1:
     $email = "bla@bla.com";
     break;


As marston said before, it's also usefull to use a default-case. The script doesn't crash (or something) when the switch gets an unknown possibility, it just uses the default-case. A default-case looks like this, and should be placed as last case in the switch:
Code:
default:
     $email = "bla@bla.com";
     break;


Greatz,
BlackSkad
kimi1974
after case You have to use :
I check it its working...
billybob
thanks its sorted now
izcool
I would recommend you to use If-Then statements instead of using Switch. I believe Switch is the old version of If-Then Statements.

- Mike.
Related topics

Need help fixing my php file
need help building a switch/case dynamically w/ a loop &
Need help with logger script. (half done)
I need help yet again
Need help wi th IPN's ....

accounts........yes i desperately need help.......^^
Need help on PHP programming....
i need help with pause code in visual basic 6
Need help understanding MySQL "Resource" type retu
need help enabling GD php extension

Need help with subdomains of my hosting account!
Need help..... somthing wrong here??
BSOD oh no! Need help
Ajax or JS - need help ASAP
PHP issues >.>

Need help - guestbook pagination like [1] [2] [3] etc.
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.