PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 14th, 2003, 12:42 PM
tobycatlin tobycatlin is offline
Hooner
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: norwich
Posts: 51 tobycatlin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
My PHP won't do case switches

I have built myself a dev server using Windows 2000 pro and running PHP and MySQL. Everything seems to be be fine execept that when i try to use a case switch it always uses the default. Then when i upload the exact same script to the host server it works fine.

The only explaination i can come up with is that i have set something up differnently to my hosting comapny.
does anyone know what this setting might be?
Thank you in advance

anyway here is the code:
PHP Code:
<?php

//include ("functions/site_functions.php");
//include ("functions/news_functions.php");

//connect_db(); 

switch ($action){ 
    default:
    echo (
"default");
    break;
    
    case 
"news_edit"
        echo (
"new_edit");
        break;
    
    case 
"news_insert"
        echo (
"new_insert"); 
        break; 
    
    case 
"news_update"
        echo (
"new_update");  
        break; 
    
    case 
"news_delete"
        echo (
"new_delete"); 
        break;
}
?>

Reply With Quote
  #2  
Old February 14th, 2003, 03:16 PM
Joe4JC Joe4JC is offline
The name's Joe. Yours?
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: Lurking in the shadows...
Posts: 147 Joe4JC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
Well, where is the variable "$action" coming from? Try this:
PHP Code:
 $action $_REQUEST['action']; 


Good luck!

Cheers,
Joe of 4Life
__________________
Check out 4Life today!

Reply With Quote
  #3  
Old February 14th, 2003, 03:18 PM
corker corker is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 18 corker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Make your default case the LAST one in the list. It should work then.

Reply With Quote
  #4  
Old February 14th, 2003, 06:15 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
firstly it doesnt matter if you call the default; option first, last anywhere!

its a matter of the value set at the switch. Have you checked its value?

try echoing it out to make sure that your var is valid

echo $action;

switch(...

Reply With Quote
  #5  
Old February 14th, 2003, 06:19 PM
tobycatlin tobycatlin is offline
Hooner
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: norwich
Posts: 51 tobycatlin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
sorry i didn't make it clear i am passing the action varable either as a hidden field in a form or a url encode.
ie case_switch.php?action=news_insert or
<input type="hidden" name="action" value="news_insert">

Reply With Quote
  #6  
Old February 14th, 2003, 06:24 PM
tobycatlin tobycatlin is offline
Hooner
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: norwich
Posts: 51 tobycatlin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
just tried echoing the action variable before the case switch and it isn't holding the action variable for some reason.
what is really puzzling is why it is working fine on my hosting server and not mine

Reply With Quote
  #7  
Old February 14th, 2003, 06:32 PM
tobycatlin tobycatlin is offline
Hooner
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: norwich
Posts: 51 tobycatlin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
hold the phone
adding $action = $_REQUEST['action']; does the job.

if anyone can be bothered to explain why this works is would like to know. But i am happy for now that it does work

PHP Code:
<?php
$action 
$_REQUEST['action'];

echo 
$action;
echo (
"<br>");
switch (
$action){ 
    default:
    echo (
"default");
    break;
    
    case 
'1'
        echo (
"new_edit");
        break;
    
    case 
'2'
        echo (
"new_insert"); 
        break; 
    
    case 
"3"
        echo (
"new_update");  
        break; 
    
    case 
"4"
        echo (
"new_delete"); 
        break;
}
?>

Reply With Quote
  #8  
Old February 14th, 2003, 07:10 PM
corker corker is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 18 corker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally posted by Ben Rowe
firstly it doesnt matter if you call the default; option first, last anywhere!


Now that's very weird. The reason I gave that answer is because a similar thing happened to me several months ago... so I checked the PHP docs and it said it had to be last. I did that and it worked then.

From the PHP documentation :
A special case is the default case. This case matches anything that wasn't matched by the other cases, and should be the last case statement.

Glad you solved it though!

Reply With Quote
  #9  
Old February 14th, 2003, 07:14 PM
tobycatlin tobycatlin is offline
Hooner
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: norwich
Posts: 51 tobycatlin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
i just moved the default case to the bottom and removed the $action = $_REQUEST['action']; line and it didn't work.

Reply With Quote
  #10  
Old February 14th, 2003, 07:22 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 17
The reason this works: $action = $_REQUEST['action'];
and this doesn't : $action

is because you probably have register globals turned off, which you should anyhow. The newer php versions come with this option off by default.

There are many ways to turn it back on, but I suggest you leave it off and always reference your get and post variables with
$_GET or $_POST


Best Regards,

--
Wil Moore III
www.wilmoore.com

Reply With Quote
  #11  
Old February 14th, 2003, 07:26 PM
tobycatlin tobycatlin is offline
Hooner
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: norwich
Posts: 51 tobycatlin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
so does that mean that the global variables i use in my functions will also not work?

Reply With Quote
  #12  
Old February 14th, 2003, 07:42 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 17
Quote:
Originally posted by tobycatlin
so does that mean that the global variables i use in my functions will also not work?


It means no variables are global until you type:

global $variablename


--
Wil Moore III
www.wilmoore.com

Reply With Quote
  #13  
Old February 15th, 2003, 08:43 AM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 650 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 34 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
it also means that you will need to use $_GET[] and/or $_POST[] if you pass anything through userforms or through the url .. or $_REQUEST[] of course.. all three of those are superglobals..

Reply With Quote
  #14  
Old February 16th, 2003, 06:17 AM
tobycatlin tobycatlin is offline
Hooner
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: norwich
Posts: 51 tobycatlin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Will the majority of hosting companies have register globals turned off? Is the PHP setup on my hosting company outdated?

Reply With Quote
  #15  
Old February 16th, 2003, 07:18 AM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 650 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 34 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
That depends on the hosting company, what version of PHP they are running, and their views on security..

I would recomend emailing them and find out what version of PHP they are using.

Reply With Quote
  #16  
Old February 16th, 2003, 12:08 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 17
Quote:
Originally posted by nicat23
I would recomend emailing them and find out what version of PHP they are using. [/B]


You could also create a file; for example "info.php", then type in:

PHP Code:
<?php
   phpinfo
();
?>



--
Wil Moore III
www.wilmoore.com

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > My PHP won't do case switches


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap