cactus Posted March 8, 2011 Share Posted March 8, 2011 Hi, I'm trying to create a cms and keep getting an undefined index:action error message. I tried to use isset but then it just threw out a different error. The section of code that is causing the errors is: if ( $_GET['action'] != "login" && $_GET['action'] != "logout" && !$_SESSION['username'] ){ //ITS SHOWING 2 ERRORS WITH ACTION ON THIS LINE login(); exit; } switch ( $_GET['action'] ) { //IT ALSO HAS AN ERROR FOR ACTION ON THIS LINE case 'login': login(); break; case 'logout': logout(); break; I would really appreciate the help as it's been annoying me and i'm having a mental blog. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/229977-undefined-index-error/ Share on other sites More sharing options...
bh Posted March 8, 2011 Share Posted March 8, 2011 Hi, try to use the isset function to check the index is defined or not! Are you sure the 'action' index is always exists? Debug your code with print_r($_GET) to check indexes... Quote Link to comment https://forums.phpfreaks.com/topic/229977-undefined-index-error/#findComment-1184467 Share on other sites More sharing options...
cactus Posted March 8, 2011 Author Share Posted March 8, 2011 I'm pretty new to PHP so I'm not entirely sure what you mean. Although I did try the isset function and it just threw out a different error message. Thanks for the reply. Quote Link to comment https://forums.phpfreaks.com/topic/229977-undefined-index-error/#findComment-1184476 Share on other sites More sharing options...
Muddy_Funster Posted March 8, 2011 Share Posted March 8, 2011 you could try more brackets: if (( $_GET['action'] != "login") && ($_GET['action'] != "logout") && (!$_SESSION['username'])){ Quote Link to comment https://forums.phpfreaks.com/topic/229977-undefined-index-error/#findComment-1184561 Share on other sites More sharing options...
kenrbnsn Posted March 8, 2011 Share Posted March 8, 2011 What was the different error? Ken Quote Link to comment https://forums.phpfreaks.com/topic/229977-undefined-index-error/#findComment-1184601 Share on other sites More sharing options...
cactus Posted March 9, 2011 Author Share Posted March 9, 2011 Hi Ken, The other error message was: Parse error: syntax error, unexpected T_IS_NOT_EQUAL, expecting ',' or ')' Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/229977-undefined-index-error/#findComment-1184938 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.