|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
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:
|
|
#2
|
|||
|
|||
|
Well, where is the variable "$action" coming from? Try this:
PHP Code:
Good luck! ![]() Cheers, Joe of 4Life ![]()
__________________
Check out 4Life today! |
|
#3
|
|||
|
|||
|
Make your default case the LAST one in the list. It should work then.
|
|
#4
|
|||
|
|||
|
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(... |
|
#5
|
|||
|
|||
|
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"> |
|
#6
|
|||
|
|||
|
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 |
|
#7
|
|||
|
|||
|
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:
|
|
#8
|
|||
|
|||
|
Quote:
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! |
|
#9
|
|||
|
|||
|
i just moved the default case to the bottom and removed the $action = $_REQUEST['action']; line and it didn't work.
|
|
#10
|
|||
|
|||
|
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 |
|
#11
|
|||
|
|||
|
so does that mean that the global variables i use in my functions will also not work?
|
|
#12
|
|||
|
|||
|
Quote:
It means no variables are global until you type: global $variablename -- Wil Moore III www.wilmoore.com |
|
#13
|
||||
|
||||
|
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..
|
|
#14
|
|||
|
|||
|
Will the majority of hosting companies have register globals turned off? Is the PHP setup on my hosting company outdated?
|
|
#15
|
||||
|
||||
|
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. |
|
#16
|
|||
|
|||
|
Quote:
You could also create a file; for example "info.php", then type in: PHP Code:
-- Wil Moore III www.wilmoore.com |