Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 19th, 2005, 02:36 PM
Registered User
 
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Switch function

switch ($action) {
    case "save_file":
       save_file();
       break;
    default:
       html_header();
       editor_page();
       html_footer();
       break;
}


I am using the above code in a script I am writing. The problem is though, the browser comes up with an error saying that it was expecting a , or a ; on line 102 which is this one - case "save_file":

I'm only starting out with this php thing so i could be missing something obivious, anyone any ideas??

 
Old January 19th, 2005, 03:37 PM
Authorized User
 
Join Date: Jan 2005
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Syntactically it is okay. I would check the few lines before the switch to make sure you have your line terminators where they should be.

 
Old January 19th, 2005, 04:39 PM
Registered User
 
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've had a look around and can't find anything. It was playing up a bit earlier aswell. I typed this on line 81:

echo "<tr><td width=30%>";

and got this:

Parse error: parse error, unexpected '>' in editor.php on line 81

I thought that that would work but...
Anyone any ideas, thanks, Chris

 
Old January 19th, 2005, 04:58 PM
Authorized User
 
Join Date: Jan 2005
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Without seeing your code, its difficult to tell what it could be. I suspect its something above line 81. Maybe you are missing a single or double quote somewhere.

 
Old January 19th, 2005, 10:58 PM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 117
Thanks: 0
Thanked 2 Times in 2 Posts
Default

hi Chrizz
the code that you gave us is:
switch ($action) {
    case "save_file":
       save_file();
       break;
    default:
       html_header();
       editor_page();
       html_footer();
       break;
}
the problem is the part that i bold it. instead of : you have to use ;

see if it works or not. let me know.

 
Old January 19th, 2005, 10:59 PM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 117
Thanks: 0
Thanked 2 Times in 2 Posts
Default

That means instead of
case "save_file":
you have to have

case "save_file";

 
Old January 20th, 2005, 06:02 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Using a semi-colon there is incorrect - it's supposed to be a colon.

http://us4.php.net/switch

-Snib - http://www.snibworks.com
Where will you be in 100 years?
 
Old January 26th, 2005, 12:38 AM
Registered User
 
Join Date: Jan 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to DeadlyDesigns.NET Send a message via MSN to DeadlyDesigns.NET Send a message via Yahoo to DeadlyDesigns.NET
Default

im assuming the reason you were getting the line error on line 81 is the %>

try echo ' '; using single quotes so you can put double quotes around 30%
echo '<tr><td width="30%">';

and in my experience it is best to do default first
and if you are using functions dont do a default instead do something like this

if(isset($_variable_to_switch))
{
switch($variable_to_switch)
{
case 'a_case':
functionname();

break; case 'a_case_2':
somethingelse();
}
}
else {
defaut_stuff_here;
}

http://www.deadlydesigns.net <--- My Baby!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Switch mamatharocks Biztalk 0 May 22nd, 2008 11:29 PM
if or switch Dink Classic ASP Databases 2 February 4th, 2007 04:00 AM
switch statement seymour_glass C# 5 January 24th, 2007 12:08 AM
Switch rajuru Beginning PHP 2 February 9th, 2005 11:24 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.