I have created a file that (hopefully) will import data from a csv file into my database but it isn't working.
require_once ('../mysql_connect.php'); //connect to the database
$filename = "Client.csv";
$fp = fopen($filename,"r");
while (!feof($fp)){
$data = fgetcsv($fp,5000);
$ClientId = $data[0];
$ConcesRef = $data[1];
$CoName = $data[2];
$Addr1 = $data[3];
$Addr2 = $data[4];
$Addr3 = $data[5];
$Town = $data[6];
$County = $data[7];
$Postcode = $data[8];
$Phone = $data[9];
$Fax = $data[10];
$sql = "INSERT INTO tblClient (ClientId, ConcesRef, CoName, Addr1, Addr2, Addr3, Town, County, Postcode, Phone, Fax)
VALUES ('$ClientId', '$ConcesRef', '$CoName', '$Addr1', '$Addr2', '$Addr3', '$Town', '$County', '$Postcode', '$Phone', '$Fax')";
$result = @mysql_query($sql)
or die(mysql_error());
}
When I first ran the code it seemed to have worked but on checking the database it had added over 18000 new records (the client.csv file has only got 25 records for testing purposes) and they were all empty apart from the first one (so it added one new record correctly but that was it).
Firstly can anyone see anything obviously wrong with the code above?
Secondly I would like to test the whole thing by echoing out $data to see whether this it can be read / recognised but I can't get it to work - any ideas how I can test this first.
thanks in advance