Ridgejp
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
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);
}
}
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.