Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8504685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:06:17+00:00 2026-06-11T02:06:17+00:00

Basically I have a piece of code that has a switch statement and some

  • 0

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 “?step=X” and then selects the appropriate function.

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…

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)

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.

<?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 .= "<?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 .= "?>";

        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) && 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->getMessage();
}

// Prepare SQL Statements
$IDB = $db->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->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->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 <br>";
                stepFunction (1);

}
function createTableSubjects ($fOT){

    global $db,$IDB2;


                echo "1 <br>";
                stepFunction (2);
}

function createTableUsers ($fOT){

    global $db,$IDB3;
    echo "3 <br>";

}

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


}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:06:19+00:00Added an answer on June 11, 2026 at 2:06 am

    Fix

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

    to

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

    You are overriding your $step variable with the global one of the same name. Thus when you come with ?step=0 you call stepFunction with 0 then it goes to createTablePages then it goes to stepFunction with 1, but is immediately replaced with 0 (because that’s what the global $step‘s value is) and again and again…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this small piece of code that basically takes a list and runs
I have been given some 'reports' from another piece of software that contains data
Hi all Basically I have a piece of code that reads the DateTime.Now values
So I have this huge tree that is basically a big switch/case with string
I have a piece of code that is executed by n threads. The code
here's my problem. I have this piece of code that sets the user location
Here I have a piece of code that should work based on what I
Basically, I have an array of keywords, and a piece of text. I am
I basically have a program that filters records from one excel file to another
I basically have a unix process running and it is doing some heavy processing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.