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

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

by
pizzipie
from LinuxQuestions.org on (#596EY)
Using Ubuntu 20.04

I can't get the select box in restoreBakup.php to show on the screen so you can make a choice. The screen shows only the header the rest is blank. console.log shows all the code to produce the options as well as the options themselves that I want to pick from. If I choose to run restoreBakup.php by itself it works fine.

Thanks for help in resolving this, R

Code://init.php calls restoreBak.php

<script type="text/javascript" >

var passwd="rick";
var database="accounts";
var file="";

// ================== Call to Ajax() ========================

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'.");
}
})
})
request.fail(function( jqXHR, textStatus ) {
alert("go see firebug");
document.write( "Request failed: " + textStatus );
})

var request2 = $.ajax({
url: "../restoreBakup.php",
type: "POST",
data: { "pwd": passwd, "db": database},
dataType: "text",
success: (function(retval){
//window.location.href='AccountsLogIn.php?file=retval';
console.log("return value "+retval);
})
});


request2.fail(function( jqXHR, textStatus ) {
alert("go see firebug");
document.write( "Request failed: " + textStatus );
});

</script>

</body>
</html>Code:

restoreBakup.php

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

?>
<!DOCTYPE html >

<html>
<head>
<title>restoreBakup.php 15Oct2020 </title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
</head>

<body>

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

<form action='' method='post'>
<select 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>

</body>
</html>

<?php

if(isset($_POST['submit'])){
if(!empty($_POST['DBase'])) {
$selected = $_POST['DBase'];
//echo 'You have chosen: ' . $pickFile[($selected-1)];
//exit();
//$choice=$pickFile[($selected-1)];
echo $pickFile[($selected-1)];
} else {
echo 'No Database to Restore ... Aborting in 5 seconds.';
sleep(5);

}
} // isset
// none of this below will work
//shell_exec(mysql-u$username -p$passwd < $choice);

//echo "finished";
?>Will not show select box on screen however, ajax success function return data shows this:

Quote:
return value

<!DOCTYPE html >

<html>
<head>
<title>restoreBakup.php 15Oct2020 </title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
</head>

<body>

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

<form action='' method='post'>
<select name='DBase'>
<option value=''>Select...</option>
<option value='1'> 2020Oct14-14:40:24_accounts.sql </option>;
<option value='2'> 2020Oct16-09:36:26_accounts.sql </option>;
<option value='3'> 2020Sep18-13:31:43_accounts.sql </option>;
<option value='4'> 2020Oct13-13:17:01_accounts.sql </option>;
<option value='5'> 2020Oct13-13:16:03_accounts.sql </option>;
<option value='6'> 2020Oct13-13:38:05_accounts.sql </option>
;
</select>
<input type='submit' name='submit' value='Get DB' >
</form>

</body>
</html>
latest?d=yIl2AUoC8zA latest?i=k2u8INVXops:NpWk3WGWhwo:F7zBnMy latest?i=k2u8INVXops:NpWk3WGWhwo:V_sGLiP latest?d=qj6IDK7rITs latest?i=k2u8INVXops:NpWk3WGWhwo:gIN9vFwk2u8INVXops
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments