Not a bone headed question. I used this for about 10 scripts before I understood what was going on. lol It is funny how you can code something and truely have no clue how it works.
The above code say basically this. If the variable $cmd has nothing set to it or does not exist. Do the code between the curly brackets { and }.
Line | Code
-----------------------------------
1 | if(!$cmd){
2 | }else if($cmd == "process_form"){
3 | }
You are now familar with Line 1. If $cmd has no value do what is inbetween { and }.
Line 2 we have
else if($cmd == "process_form"){
this is saying
else - $cmd has a value
if($cmd == - $cmd is a perfect match for (use 1 "=" for un perfect matches(not ideal for security))
"process_form" - the name that was passed in the $cmd variable.
and Line 3 I think you will get.
Now how do we set the $cmd value? Where did I get $cmd from?
First off $cmd can be anything. $cmd could easily be $deez_nuts or $action or anything you want it to be. To se the value you could use the form tag..
<form action="http://somesite.com/form.php?cmd=process_form" method="POST">
notice the "?cmd=process_form."
You could also use a hidden input tag
<input type="hidden" name="cmd" value="process_form">
or even a select element
<select name="cmd">
<option value="process_form">Process option 1</option>
<option value="process_form2">Process option 2</option>
<option value="process_form3">Process option 3</option>
</select>
Now you can get reall tricking and have this also...
if(!$cmd){
//provide a form
}else if($cmd == "process_form"){
if(!$action){
//do basic form process
}else if($action == "advanced"){
//do advance form process
}//end action variables
}//end cmd variables
Just remeber to keep them nested and keep the code easy to read for yourself. Nothing suck more than trying to find that bug through 10,000 lines of code and it is all aligned left.