0

When i uploading .csv file Load data infile query is not working.

My php code is:

include "../../connection.php";
if ($_FILES["file"]["error"] > 0) {
    echo "Error: " . $_FILES["file"]["error"] . "<br>";
} else {
    echo "Upload: " . $_FILES["file"]["name"] . "<br>";
    echo "Type: " . $_FILES["file"]["type"] . "<br>";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br>";
    echo "Stored in: " . $_FILES["file"]["tmp_name"];
    echo '<br>';
    $a = $_FILES["file"]["tmp_name"];
    $csv_file = str_replace("\\", "/", "$a");
    echo $csv_file;
    echo '<br>';
    $query = "LOAD DATA INFILE '$csv_file' INTO TABLE `competency_questions` FIELDS TERMINATED BY ',' ENCLOSED BY '\"' ESCAPED BY '\\' LINES TERMINATED BY '\r\n'";
    $s = mysql_query($query);


    if ($s) {
        echo "<script>alert('Record successfully uploaded.');window.location.href='../../view all test.php?id=$cid';</script>";
    } else {
        echo 'Failed';
    }
}

And It shows Failed Error.

Image

Anyone Help me to resolve this issue?

srini vasan
  • 85
  • 1
  • 1
  • 8
  • Please first do a `var_dump($csv_file)` and check if these data is available or not on your CSV and is that data properly loading or not and i think there is something wrong with your query – Code Cooker May 13 '17 at 07:50
  • You may check this link for your help [MYSQL Import data FROM Excel](http://stackoverflow.com/questions/14127529/mysql-import-data-from-csv-using-load-data-infile) – Code Cooker May 13 '17 at 07:53
  • Thank you ...I will check..@Smalldeveloper – srini vasan May 13 '17 at 08:01

0 Answers0