So the full code actually needs to be this:
<?php
include('dbconnect.php');
$file = fopen("demo.csv","r");
// Read and throw away the header row
fgetcsv($file);
$stmt = $pdo->prepare("INSERT INTO members (name, residential_address, mailing_address, precinct, age, ethnicity, gender, party, race, phone) VALUES (:name, :residential_address, :mailing_address, :precinct, :age, :ethnicity, :gender, :party, :race, :phone)");
while (! feof($file)) {
$row = fgetcsv($file);
$stmt->bindParam(':name', $row[0]);
$stmt->bindParam(':residential_address', $row[1]);
$stmt->bindParam(':mailing_address', $row[2]);
$stmt->bindParam(':precinct', $row[3]);
$stmt->bindParam(':age', $row[4]);
$stmt->bindParam(':ethnicity', $row[5]);
$stmt->bindParam(':gender', $row[6]);
$stmt->bindParam(':party', $row[7]);
$stmt->bindParam(':race', $row[8]);
$stmt->bindParam(':phone', $row[9]);
$stmt->execute();
}
fclose($file);
?>
right?
EDIT
I changed the code and tested it. The import works, but this happens in my database:
Why is a third record being made with no values in it? The csv
only has 2 records…?