Lodder
Lodder

Reputation: 19733

PHP cases work but not default

I have a few cases for pages which are being loaded using Ajax. Each case loads perfectly apart from the default at the bottom. It just doesn't display anything.

switch($_GET['page'])  {  

    case '#filemanager' : $page = '
        <div class="innerbox">
            <p>Demo text for the file manager page</p>
        </div>'; break;

    case '#todo' : $page = '
        <div class="innerbox">
            <p>Demo text for the to-do page</p>
        </div>'; break;

    default: $page = '
        <div class="innerbox">
            <h1>ADMIN CONTROL PANEL</h1>
        </div>'; break;

}
echo $page;

Is there something wrong I have done in the code? If so a quick helping hand would be much appreciated.

Regards

Upvotes: 1

Views: 90

Answers (1)

jeroen
jeroen

Reputation: 91742

The code should work, see this example.

Most likely the problem is that $_GET['page'] is not set and you run into a php warning. You can avoid that by using:

$get = isset($_GET['page']) ? $_GET['page'] : 'default or something';
switch($get) {
    ...

Upvotes: 3

Related Questions