Hello
I need to addslashes to a .csv file inorder to get the data into the mysql database
I have tried a couple of ways but get a wide variety of error messages - need to get my head around this, can someone pleae help
the latest way I have though of doing it is below, but this doesn;t work - I don't get any error messages but the data isn;t added to the database - I just get one empty record added.
require_once ('../mysql_connect.php'); //connect to the database
$uploadDir = '/home/***/***/htdocs/***/***/upload/';
$uploadFile = $uploadDir . $_FILES['ClientCsvFile']['name'];
print "<pre>";
if (move_uploaded_file($_FILES['ClientCsvFile']['tmp_name'], $uploadFile))
{ echo '<div align="center">
<p> </p>
<p> </p>
<p><b><font color="#FF0000" face="Arial, Helvetica, sans-serif" size="4">Thank You, <br> The new Client Data has been added to the database</font></b></p>
</div>';
}
else
{
print "Not Possible To Upload Data! Please Try Again";
}
print "</pre>";
$filename = $uploadFile;
$fp = fopen($filename,'wb') or die('could not open file!');
while (!feof($fp)){
$data = fgetcsv($fp,100000000);
$ClientId = addslashes($data[0]);
$ConcesRef = addslashes($data[1]);
$CoName = addslashes($data[2]);
$Addr1 = addslashes($data[3]);
$Addr2 = addslashes($data[4]);
$Addr3 = addslashes($data[5]);
$Town = addslashes($data[6]);
$County = addslashes($data[7]);
$Postcode = addslashes($data[8]);
$Phone = addslashes($data[9]);
$Fax = addslashes($data[10]);
$sql = "REPLACE 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());
}