Can't get php script to show select box from program in firefox - console.log shows code including results I want

pizzipie

New Member
Joined
Sep 20, 2020
Messages
13
Reaction score
8
Credits
230
I'm going nuts!!! This all makes no sense to me. Here is my scheme that doesn't work.

'init.php' checks for MySql to have the database we want to access. If MySql it does not contain the database the program calls, through Ajax, 'restoreBakup.php' which is supposed to present a 'select box' to choose a bakup file for restoring the database into MySql. However, the 'select box' never presents itself on the screen !!!. Using 'web developer tools' you see the 'select box' complete with the correct options in console.log.
So the Present action of this application is that 'init.php' is run, finds the database is not contained in MySql and calls 'restoreBakup.php' which bypasses the 'select.box' on the screen and which then calls 'restoreMySql.php' which skips all the contained code and returns 'nothing' to the original Ajax call in init.php.

'restoreBakup.php' works fine if you call it by itself with firefox.

Thanks in advance for any help in solving this, R

init.php
PHP:
<h3>Checking for Existing Database 'accounts'</h3>
</p>


<script type="text/javascript" >

$(function() {
  
var passwd="rick";
var database="accounts";
var file="";

// ================== 1st and Only Call to Ajax() Now ========================

var request = $.ajax({
    url: "chkDB.php",
    type: "POST",
    data: { "pwd": passwd, "db": database},
    dataType: "text" ,
        success: (function(retval) {
            if (retval=='found') {
                  window.location.href='AccountsLogIn.php'; 
            } else {
               alert(database +" Was not found ... Trying 'restoreBakup'.");
               window.location.href="../restoreBakup.php"
                
            } // else 
        }) // success from 1st call 
}) // end ajax-1

     request.fail(function(jqXHR, textStatus ) {
       alert("go see firebug");
        document.write("Request failed: " + textStatus ); 
    }) 
// ===========  End 1st Call ============


}); // ready

</script>



</body>
</html>

restoreBakup.php
PHP:
Code:


<?php


// restoreBackup.php  pick a database to restore into MySql ...


include './include/myPhpFunctions.inc';


error_reporting(-1);

ini_set("display_errors", true);


   $hostname = "localhost";

   $database = "accounts";

   $username = "rick";

   $passwd = "rick";

   $row=array();

  

$directory='./bakups';

$pickFrom=$pickFile=array();

$selected;


//echo getcwd(); exit();


// Open the directory, and read its contents

if (is_dir($directory)){

  if ($fh = opendir($directory)){

    while (($file = readdir($fh)) !== false){

        if($file=="." || $file=="..") {continue;}

        //echo $file;

        $pickFile[]=$file;

    }

    closedir($fh);

  }

}


//  ==================================================================================

//  Need function here to abort and go back to index.html if no databases in bakup file

//  ===================================================================================


?>

<!DOCTYPE html >


<html>

    <head>

        <title>restoreBakup.php 15Oct2020 </title>

        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />


            <script  type="text/javascript" src="./jquery/jquery-1.9.1.js"> </script>

    </head>


<body> 


<h2>Pick A Database to Restore.</h2>


<form id="frm1" action="" method='post'>

<select id="mySelect"  name='DBase'>

<option value=''>Select...</option>


<?php

    for($i=0; $i<count($pickFile); $i++) {

?>     

      <option value='<?php echo ($i+1) ?>'> <?php echo $pickFile[$i] ?> </option>;

    

<?php } ?>


</select>


<input type='submit' name='submit' value='Get DB' >


</form>



<script type="text/javascript" >


var choice="";

var database="accounts";


$(function() {              // BELOW - on submit do the following

  

$("#frm1").submit(function(event ) {

    alert("Inside submit()");                        // NEVER HAPPENS

      event.preventDefault();

      choice=$("#mySelect option:selected").text();

})     

       // ================== 1st & Only Call to Ajax() Now ========================


var request = $.ajax({

    url: "restoreMySql.php",

    type: "GET",

    data: { "pwd": "rick", "db": choice},

    dataType: "text" ,

        success: (function(retval) {

            if (retval=='ok') {

                  window.location.href='AccountsLogIn.php'; 

            } else {

               alert(" Restoring MySql "+database+" ... Was not successful.");

               window.location.href="../index.html"

                

            } // else 

        }) // success from 1st call 

}) // end ajax-1


     request.fail(function(jqXHR, textStatus ) {

       alert("go see firebug");

        document.write("Request failed: " + textStatus ); 

    }) 

// ===========  End 1st Call ============



})     

</script>


</body>

</html>

restoreMySql.php
PHP:
<?php

// restoreMySql.php starts mysql and reads database into itself thus re-creating missing database

echo "Inside restoreMySql.php ";   // ZIPS by this and returns to the Ajax call in init.php

echo"<pre>";

print_r($_POST);

echo "</pre>";

//shell_exec(mysql-u$username -p$passwd < $choice);

// (exec to AccountsLogIn.php

?>
 

Members online


Top