Can anyone help
I have some code that takes a csv file and uploads the data contents into mysql database.
However the first time you perform the command to run the code I get the 'thank you, your data has been uploaded' message, but checking on the database nothing has been changed / added.
But if you go straight back to the website and perform the operation again - no changes, just hit the upload button - it works fine and updates the database.
I need to get this sorted (if I suggest to my client that the only way for this to work is to do everything twice I will not be popular!)
Has anyone come across this before
I have no idea where to start........
the code is
session_start ();
$_SESSION['username'] = $username;
require_once ('../mysql_connect.php'); //connect to the database
$uploadDir = '/home/xx/xx/htdocs/xx/xx/upload/';
$uploadFile = $uploadDir . $_FILES['SectionCsvFile']['name'];
print "<pre>";
$filename = $uploadFile;
$fp = fopen($filename,"rb") or die('could not open file!');
while (!feof($fp)){
$data = fgetcsv($fp,500000);
$SectionId = addslashes($data[0]);
$ClientRef = addslashes($data[1]);
$SectionName = addslashes($data[2]);
$sql = "REPLACE INTO tblSection (SectionId, ClientRef, SectionName)
VALUES ('$SectionId', '$ClientRef', '$SectionName')";
$result = mysql_query($sql)
or die(mysql_error());
}
if (move_uploaded_file($_FILES['SectionCsvFile']['tmp_name'], $uploadFile))
{ echo '<div align="center">
<p><b><font color="#FF0000" face="Arial, Helvetica, sans-serif" size="4">Thank You, <br> The new Section Data has been added to the database</font></b></p>
</div>';
}
else
{
print "Not Possible To Upload Data! Please Try Again";
}
print "</pre>";