0

I have a problem with my Import File in PHP. I Have this code:

if(isset($_POST["Import"])){


    $filename=$_FILES["file"]["tmp_name"];
    if($_FILES["file"]["size"] > 0)
    {
        $file = fopen($filename, "r");
        $data = fgetcsv($file, 0, '|');

        while (($data = fgetcsv($file, 10000, "|")) !== FALSE)
        {
            $sql = "INSERT INTO
                    uanf_ver
                    (
                    r,
                    c,
                    l,
                    cr,
                    pr,
                    es,
                    ro,
                    bo,
                    cc,
                    sc,
                    lp,
                    cl,
                    sl
                    ) 
                   values (
                   '".addslashes($data[0])."',
                   '".addslashes($data[1])."',
                   '".addslashes($data[2])."',
                   '".addslashes($data[3])."',
                   '".addslashes($data[4])."',
                   '".addslashes($data[5])."',
                   '".addslashes($data[6])."',
                   '".addslashes($data[7])."',
                   '".addslashes($data[8])."',
                   '".addslashes($data[9])."',
                   '".addslashes($data[10])."',
                   '".addslashes($data[11])."',
                   '".addslashes($data[12])."'
                   )";
            $result = mysqli_query($conn, $sql);
        }

        fclose($file);
    }
}

The problem is when i load file with 1 line is not read. If i upload 3 lines the last line is not read and is not insert in database. Have any idea how can i fix this?

1 Answer 1

1

I resolved the problem.

        $data = fgetcsv($file, 0, '|');

this part need to be deleted and need to remain on the while

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.