Is this possible?
I want to strip some character out of a csv file prior to adding the data to mysql database.
when users have input client data they have used ' ` and other characters that are mucking up the data insert into the database.
I want to strip these out - can I use ereg_replace ?
I have tried the following code but I get the error message 'Warning: fopen(Client csv): failed to open stream: No such file or directory in /home///htdocs///upload/client_upload.php on line 26
could not open file!' - line 26 is $fp = fopen($filename,"rb") or die('could not open file!');
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 = "Client.csv";
$filename = ereg_replace( "(([`\'/\\.]))", " ", $filename);
$fp = fopen($filename,"rb") or die('could not open file!');
while (!feof($fp)){
$data = fgetcsv($fp,100000000);
$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 = "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());
}
what should I do?