Reputation: 141
i'm creating a restore database script in php but its not working. this is the code so far
<form action = '' method = 'POST'>
<h2>Restore</h2>
<table>
<tr><td><input type=file name="file"></td></tr>
<tr><td><input type = 'submit' name = "restore" value="restore"></tr></td>
</table>
</form>
<?php
$host = 'localhost';
$user = 'root';
$pass = ' ';
$dbname = 'itravel';
//date_default_timezone_set('Asia/Kuala_Lumpur');
//$currentdate = date('YmdGis');
$restore_name = $_POST['file'];
$custompath = $_POST['path'];
if(isset($_POST['restore']))
{
$restore = "c:/xampp/mysql/bin/mysql -h $host -u $user $dbname < $backup_name";
system($restore);
}
?>
nothing happening after clicking the restore button. please help
Upvotes: 0
Views: 446
Reputation: 360872
$restore = "c:/xampp/mysql/bin/mysql -h $host -u $user $dbname < $backup_name";
^^^^^^^^^^^
nowhere do you define $backup_name
. Shouldn't it be $restore_name
?
Uploads also do not appear in $_POST
. They show up via $_FILES
.
You should also NEVER assuming an upload succeeded. Especially for a mysql dump file. It is possible that the upload was truncated, yet you blindly feed the file back into MySQL, which could leave you with a partially/totally trashed database.
ALWAYS check for upload errors:
if ($_FILES['files']['error'] !== UPLOAD_ERR_OK) {
die("Upload failed with error " . $_FILES['files']['error']);
}
$restore_name = $_FILES['files']['tmp_name']; // temp file PHP stores upload in
Upvotes: 2