So here's what I'm trying to do. switch($_GET['fuseaction']) { case'add' : /* ... */ break; /*...*/ } PHP: So if the fuseaction corresponding case doesn't exist, the script will die. Please help!
use default switch($_GET['fuseaction']) { case'add' : /* ... */ break; default: /*...*/ } PHP: also same if you use if else, like this: if ($_GET['fuseaction'] == "add") { /* ... */ } elseif ($_GET['fuseaction'] == "insert") { /* ... */ } else { /* ... */ } PHP: more info check here: http://www.php.net/manual/en/control-structures.switch.php i like to use if else than switch
I am using default already. But I want to kill the script if fuseaction takes a value that doesn't have a corresponding case. Do you know what I mean? ... // user typed example.com/page.php?fuse=foo $caseValue = $_GET['fuse']; case 'blah' : // ... break; case'new' : // ... default : break; // ... PHP: Since there was no case'foo' I want to throw an error
In that case, don't just break the conditional, kill the script with die(): ... // user typed example.com/page.php?fuse=foo $caseValue = $_GET['fuse']; case 'blah' : // ... break; case'new' : // ... default : die("I don't know how to handle $fuseaction\n"); // ... PHP:
I guess that will work. I didn't want to use it in default though. I was gonna use that for something else.