FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free 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
php variables
Programming Help & Support Guidelines
php script in php nuke - need help!
[HELP] PHP -> Scripting
Needing a Bit Og Help {PHP}!
need help building a switch/case dynamically w/ a loop &
Need help integrating html code into php
PHP Help please
mySQL Query/PHP code - get the highest value...
need help with this code
<?php switch ($sayfa)
Need Help With This Code!
[HELP] PHP (and some MyBB) Administration
Error with MySQL and PHP script in my CMS
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

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