0

I want to implement this script: http://www.daniloaz.com/en/560/programming/backup-de-bases-de-datos-mysql-con-php/

on my website to backup all the database at the end of the day.

May I know is it possible for me to put a button to click and run the script and echo the status after it finish without refreshing the page or bring me to a new page.

as at the moment i everyday need to go to the link: www.example.com/backup.php to do daily backup, I want this to ease my job :)

any idea how to do this?

Jeff
  • 111
  • 2
  • 3
  • 11

1 Answers1

0

what type of button? if html yes it's easy

have a button on what ever page you want along with a div like so:

<input type="button" name="perform_backup"  onclick="do_backup()"><div id="results"> No backup has been performed yet</>

then have a javascript which calls your backup php script like this

<script>  
 function do_backup(){
   var xhReq = new XMLHttpRequest();
   var request = "http://www.example.com/backup.php " // this will prepare a request to your server
   xhReq.open("GET", request, false);  // send a request
   xhReq.send(null);
   document.getElementsByID("results").innerHTML=xhReq.responseText  /// this will display results

   }
</script>

then I would modify the script on your server to give more then a boolean variable but that's up to you. But whatever you choose it will be seen inside <div id="results"> , without loading a new page... This method is called AJAX for future questions

brendosthoughts
  • 1,683
  • 5
  • 21
  • 38
  • but if already perform will it the result show "done" or "error" if the backup unsuccessfull? – Jeff May 07 '13 at 01:34
  • it will show true or false , as that's what the php code return so false will show 0 in php and true something else ... though if you modify that code you can make it show whatever you want – brendosthoughts May 07 '13 at 04:32
  • sorry, im totally don't know ajax, but i use all the code provide by you, the button was nothing and when i click it nothing run. by the way i did change www.example.com to my web address but not working – Jeff May 07 '13 at 14:51
  • Have you tested the php script not using my code? If it works... Try typing in the url address in a Web browser and eye what happens – brendosthoughts May 08 '13 at 21:46
  • Btw... This solution will have serious security problems, I assume you know this / have address them somehow – brendosthoughts May 08 '13 at 21:47