Zachary Tyler Wiggins
Zachary Tyler Wiggins

Reputation: 19

php switch am I doing it wrong?

I'm trying to make multiple pages in 1 file and i have this

<?

switch($action){
    case "add":
       add();
       break;
    default:
       hello();
       break;
}

function add() {

    echo "hello";
}

function hello() {

    echo "hello1";
}
?>

but when I got to ****.php?action=add I still get "hello1"

what am I doing wrong with this to where I get hello

Upvotes: 0

Views: 213

Answers (2)

internals-in
internals-in

Reputation: 5038

 <?php


       $action=  $_GET['action']
       //$_REQUEST, by default, contains the contents of $_GET, $_POST and $_COOKIE. 
       // $action=  $_REQUEST['action']; 
        switch($action){
            case "add":
               add();
               break;
            default:
               hello();
               break;
        }

        function add() {

            echo "hello";
        }

        function hello() {

            echo "hello1";
        }
        ?>

Upvotes: 0

sidoh
sidoh

Reputation: 590

switch on $_GET['action'] instead.

Upvotes: 1

Related Questions