unexpected Inifite loop using switch and some function
<p>Basically I have a piece of code that has a switch statement and some functions. It goes to the switch statement using a parameter given by the browser "<code>?step=X</code>" and then selects the appropriate function. </p>

<p>My problem is even when at the end of each function I specify to go to the next switch statement it never does it and somehow it becomes an infinite loop of the function that I selected with the "step=x" in the browser...</p>

<p>Why is getting stuck in 1 function and not iterating through them? (the code for the step is highlighted at the end of the script)</p>

<p>I get the output in the browser of any selected function. so It enters the switch and the selected function... but then it becomes and infinite loop because in the broswer i get 300 of the same echo statements. It is never able to iterate through them or exit the selected function.</p>

<pre><code>&lt;?php 
//DB Config File
$dbFile = 'dbconfig.php';

$username = $_GET['username'];
$password = $_GET['password'];
$server = $_GET['server'];
$dbname = $_GET['dbname'];
$step = $_GET["step"];





function createfile ($dbFile) {
        //Creates File and populates it.
        $fOpen = fopen($dbFile, 'w');
global $username, $password, $server, $dbname;
            $fString .= "&lt;?php\n";
            $fString .= "// Database Constants\n";
            $fString .= "\$DB_SERVER =" . "\"" . $server . "\";\n";
            $fString .= "\$DB_USER =" . "\"" . $username . "\";\n";
            $fString .= "\$DB_PASS =" . "\"" . $password . "\";\n";
            $fString .= "\$DB_NAME =". "\"" . $dbname . "\";\n";
            $fString .= "?&gt;";

        fwrite($fOpen, $fString);
        fclose($fOpen);
return true;
}




try {
$db = new PDO ('mysql:host=' .$server.';dbname='.$dbname,$username,$password);

if ($db) { //if succesful at connecting to the DB

if (file_exists($dbFile)){
    if (is_readable($dbFile) &amp;&amp; is_writable($dbFile)){ 

        //Creates File, populates it and redirects the user

    if (createfile($dbFile)) { 
    echo "nelxt";
    stepFunction($step);
    exit ();
            }


        } else { 

        echo "The file {$dbFile} cannot be accessed. Please configure the file manualy or grant Write and Read permission.";  }

    } else {

        //Creates File, populates it and redirects the user

    if (createfile($dbFile)) {

    echo "next";
        stepFunction($step);
    exit ();
            }

        }


}

} catch (PDOException $e) { //Catchs error if can't connect to the db.
    echo  'Connection failed: ' . $e-&gt;getMessage();
}

// Prepare SQL Statements
$IDB = $db-&gt;prepare( 
 "CREATE TABLE pages (
  id int(11) NOT NULL auto_increment,
 subject_id int(11) NOT NULL,
  menu_name varchar(30) NOT NULL,
  position int(3) NOT NULL,
  visible tinyint(1) NOT NULL,
  content text NOT NULL,
  PRIMARY KEY  (id)
)ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=utf8");

$IDB2 = $db-&gt;prepare("
CREATE TABLE subjects (
  id int(11) NOT NULL auto_increment,
  menu_name varchar(30) NOT NULL,
  position int(3) NOT NULL,
  visible tinyint(1) NOT NULL,
  PRIMARY KEY  (id)
)ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=utf8");

$IDB3 = $db-&gt;prepare("
CREATE TABLE users (
  id int(11) NOT NULL auto_increment,
  username varchar(50) NOT NULL,
  hashed_password varchar(40) NOT NULL,
  PRIMARY KEY  (id)
)ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8");

//Set Option to True or False
if (empty ($_GET['fot']) ) { 
    $fOT = false; 
    } else { $fOT = true;
        }

///////////////////////////////
// PROBLEMATIC STEP BEGINS HERE 
///////////////////////////////

function createTablePages (){

    global $db,$IDB;

                echo "0 &lt;br&gt;";
                stepFunction (1);

}
function createTableSubjects ($fOT){

    global $db,$IDB2;


                echo "1 &lt;br&gt;";
                stepFunction (2);
}

function createTableUsers ($fOT){

    global $db,$IDB3;
    echo "3 &lt;br&gt;";

}

function stepFunction ($step,$fOT){
global $db,$IDB1,$IDB2,$step,$fOT;



switch ($step) {
    case 0: echo "hola";
            createTablePages ($fOT);
            break;
    case 1: echo "hola2";
            createTableSubjects($fOT);
            break;
    case 2: createTableUsers ($fOT);
            break;
    }


}
?&gt;
</code></pre>
