I see that you are keep reusing the same array for your queries array($_POST['step1']['tb_prefix'], $config_name)
I would suggest to dehydrate your code by declaring a separate variable in the function $queryParams or something like that which would be equal to this array and used in queries.