Avatar of Ridgejp
Ridgejp
Flag for United Kingdom of Great Britain and Northern Ireland asked on

CSV Data Import without Header Row

Hi,

I'm using PHP to import a csv file using the following code ... the mapping to all the fields isn't yet complete I'm just testing the logic. However, I need to omit the first row as it's pulling in the header data for the file which isn't need.

How do I do that?

J

<!DOCTYPE html>
<?php include("connection_1.php"); 


    if(isset($_POST['submit']))
        
    {
        
        $file = $_FILES['file']['tmp_name'];
        
        $handle = fopen($file,"r");
        
        while(($fileop = fgetcsv($handle,1000,",")) !== false)
        
            {
            
            $sales_record_number = $fileop[0];
            $user_id = $fileop[1];
            $buyer_email = $fileop[4];
            $buyer_name = $fileop[2];
            $buyer_phone = $fileop[3];
            $add_1 = $fileop[5];
                
            $query = "INSERT into holding_ebay 
                                        
                                        (    sales_record_number
                                            ,user_id
                                            ,buyer_email
                                            ,buyer_name
                                            ,buyer_phone
                                            ,add_1) 
                                            
                                            VALUES
                                            
                                        (   '$sales_record_number'
                                            ,'$user_id'
                                            ,'$buyer_email'
                                            ,'$buyer_name'
                                            ,'$buyer_phone'
                                            ,'$add_1')";
            mysqli_query($link, $query);
            
            }
                
            if (mysqli_query($link, $query))    {
                    echo "The data import was successful";
                                                }
else {
  echo "The data import failed with the following error: " . mysqli_error($link);
}
    }
    
?>

Open in new window

PHPMySQL Server

Avatar of undefined
Last Comment
Julian Hansen

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Julian Hansen

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23