简体   繁体   中英

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

改为启用$_GET['action']

 <?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";
        }
        ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM