papillonstudios Posted September 28, 2009 Share Posted September 28, 2009 I am using a switch statement on my my site but when i declare the variable "action" to use with the switch statement and use the $_GET method to retrieve it. Heres my error Notice: Undefined index: action in /Users/GamingFusion/Documents/Theatre311/config.php on line 49 Heres my code $action = secure($_GET['action']); secure(); is a function i made whats wrong? if you need anymore info or code i will post it. Quote Link to comment Share on other sites More sharing options...
Alex Posted September 28, 2009 Share Posted September 28, 2009 You're getting this because there is no index of action in the super-global $_GET. More specifically, there is no 'action' variable defined in your query string. file.php // Error file.php?action=something // No error Edit: Solution: Check to make sure it's set before assigning that value to $action" if(isset($_GET['action'])) { $action = secure($_GET['action']); } Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 28, 2009 Share Posted September 28, 2009 If you have a variable that optionally might or might not exist at the time your code is executed, you need to use isset() to test if it does exist. It is common to use code like the following to give such an optional variable the actual value or a default value so your code will behave in a predictable manor when the variable does not exist - $action = isset($_GET['action']) ? secure($_GET['action']) : ''; // pick a default value (and empty string in this example) that makes sense in your application Quote Link to comment Share on other sites More sharing options...
papillonstudios Posted October 2, 2009 Author Share Posted October 2, 2009 ok thanks guys for the replys. I ahve been going through the script because it was working before thing is messed up on everypage i get these errors Notice: Undefined index: dldesc in /Users/GamingFusion/Desktop/Isus 2.0/config.php on line 58 Notice: Undefined index: username in /Users/GamingFusion/Desktop/Isus 2.0/config.php on line 62 Notice: Undefined index: password in /Users/GamingFusion/Desktop/Isus 2.0/config.php on line 63 Notice: Use of undefined constant guest - assumed 'guest' in /Users/GamingFusion/Desktop/Isus 2.0/config.php on line 91 Notice: Use of undefined constant guest - assumed 'guest' in /Users/GamingFusion/Desktop/Isus 2.0/config.php on line 92 Notice: Undefined index: action in /Users/GamingFusion/Desktop/Isus 2.0/config.php on line 99 Notice: Undefined index: sa in /Users/GamingFusion/Desktop/Isus 2.0/config.php on line 100 Notice: Undefined index: ssa in /Users/GamingFusion/Desktop/Isus 2.0/config.php on line 101 Notice: Undefined index: action in /Users/GamingFusion/Desktop/Isus 2.0/index.php on line 27 and for the login page for example Notice: Use of undefined constant text - assumed 'text' in /Users/GamingFusion/Desktop/Isus 2.0/login.php on line 22 Notice: Use of undefined constant username - assumed 'username' in /Users/GamingFusion/Desktop/Isus 2.0/login.php on line 22 Notice: Use of undefined constant password - assumed 'password' in /Users/GamingFusion/Desktop/Isus 2.0/login.php on line 23 Notice: Use of undefined constant password - assumed 'password' in /Users/GamingFusion/Desktop/Isus 2.0/login.php on line 23 and i havent changed a thing but the one online works fine http://isus.gamingfusion.net/demo Quote Link to comment Share on other sites More sharing options...
sawade Posted October 2, 2009 Share Posted October 2, 2009 For the undefined index... continue what Alex said previously. Include all variables under the isset(). That should take care of those for you. Quote Link to comment Share on other sites More sharing options...
papillonstudios Posted October 2, 2009 Author Share Posted October 2, 2009 I looked at my local server more and its the server but i dont know how to fix it. It works fine when online but not on my server. but ya i should do that anyway Quote Link to comment Share on other sites More sharing options...
Philip Posted October 2, 2009 Share Posted October 2, 2009 It's because you have different configurations in your php.ini files, one to probably hide all the warning/notices and the other to show all. Undefined index is when you try to call a value from an array, who's key does not exist in the array. $array = array('hi' => 'hello', 'test' => 'testing', 'foo' => 'bar'); echo $array['foo']; // works, because foo is a valid key echo $array['joebob']; // will throw a notice, because we never defined the key 'joebob' echo $array['hi']; // works, again because we defined it. As for: Notice: Use of undefined constant, its when you don't use quotes around the key/index name. Without the quotes its considered a constant, and PHP then looks for the constant, and when it doesn't find it, it is smart enough to realize you meant it with quotes. See this example below, the first is correct, the second looks for a constant named foo first. $array = array('hi' => 'hello', 'test' => 'testing', 'foo' => 'bar'); echo $array['foo']; // right echo $array[foo]; // wrong Quote Link to comment Share on other sites More sharing options...
papillonstudios Posted October 3, 2009 Author Share Posted October 3, 2009 Problem solved i have decided to recode the entire thing. I was going to do it sometime Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.