0

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

5
  • What are you getting with get_mime_type()? You need to debug this somewhat yourself. There isn't enough to go off of here. Commented Mar 4, 2013 at 14:50
  • Any chance you could look at the log and see what c:/xampp/mysql/bin/mysql -h $host -u $user $dbname < $backup_name returns (or the return value of the system() call)? Commented Mar 4, 2013 at 14:52
  • Yet another "debug my code for me" question... but of course it's PHP blamed for this Commented Mar 4, 2013 at 14:53
  • See if this helps you. stackoverflow.com/q/14799987/827224 Commented Mar 4, 2013 at 15:07
  • @YourCommonSense i'm just asking for help. i tried a lot of things. i know this script was working before. it just went like this. Commented Mar 5, 2013 at 2:47

1 Answer 1

2
$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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.