tags:

views:

51

answers:

4

receiving error: PHP Notice: Undefined index: mode in /web/ee_web/include/form-modal.php on line 51

line 51

switch($_GET["mode"]) {

block of code it is in:

switch($_GET["mode"]) {
    case "login":
    login_user();
    break;

    case "logout":
    session_destroy();
    print "<p>You are now logged out.</p>";

    print "<p><input type=\"submit\" id=\"closeButton\" name=\"closeButton\" value=\"Close\"  onclick=\"self.parent.tb_remove(); parent.location.reload(1);\" /></p>";
    break;

    default:
    login_user();
    //print "<p>How'd you end up here?</p>";
    break;
}

The URL for the page is index.php?mode=logout, that is how I am passing the value into mode.

Any way I could resolve this error message?

+2  A: 

Wrap it into an if like

if( isset($_GET['mode'])) { switch ... } else { print_r($_GET); }

to see what are you actually getting.

Kemo
A: 

With the combination of url and code, the only thing I can think of is that perhaps you are using a framework that is not allowing GET.

I know that for example CodeIgniter has GET disabled by default.

Doing a var_dump(GET) at the top of your page should tell you more as well.

jeroen
+1  A: 

I don't see the problem. But in the interest of cleaner code + trouble shooting, you might try:

$this_mode = $_GET["mode"];
switch($this_mode) {
Smandoli
The 3 answers so far make sense to me, and I would put Kemo's plus mine together
Smandoli
+1  A: 

I would give a default value for it:

if (!isset($_GET['mode']) $_GET['mode'] = "login";

switch($_GET["mode"]) {

    case "logout":

    session_destroy();
    print "<p>You are now logged out.</p>";

    print "<p><input type=\"submit\" id=\"closeButton\" name=\"closeButton\" value=\"Close\"  onclick=\"self.parent.tb_remove(); parent.location.reload(1);\" /></p>";
    break;

    case "login" :    
    default:

    login_user();
    //print "<p>How'd you end up here?</p>";
    break;
}

Plus, instead of duplicating the code for case 'login': and default: you can put them together like that.

nickf