What is wrong with this code ??
Nothing happens, no update, no insert, no error..
Please review and enhance.. getting bold spots..
Thanks a lot !
Code: Select all
<?php
mysql_select_db($database_ASN, $ASN);
$csv = file("UploadedMatch.csv"); //this puts each line of the file into it's own element of the array "$csv"; $csv[0] is the field names, $csv[1] is the first row of data, etc.
$count = count($csv);
for ($x = 1; $x<$count; $x++)
{
list($Id, $Naam, $Voornaam, $ASNNR, $Datum_lid, $URL, $Vereniging, $Adres, $Postcode, $Woonplaats, $Telnr, $Email, $Oud_Sefnr) = explode(';',$csv[$x]);
$query = "select * from testtable where Id = $Id"; //this is just to see if that data row already exists in the table
$result =mysql_query($query) or die(mysql_error());
while
($row = mysql_fetch_assoc($result))
{
$rc = mysql_count_rows($result);
if ($rc == 1)
{
$q = 'update testtable set ';
$qend = " where Id='" . $Id . "'";
$qtmp = array(); // make sure this is empty
foreach ($row as $columnname => $value)
if ($value != $$columnname)
$qtmp[] = "$columnname = '$$columnname'";
}
else
{
$q = 'insert INTO testtable';
$qend = '';
$qtmp = array();
foreach (array($Id, $Naam, $Voornaam, $ASNNR, $Datum_lid, $URL, $Vereniging, $Adres, $Postcode, $Woonplaats, $Telnr, $Email, $Oud_Sefnr) as $col)
$qtmp[] = $col . "='" . $$col . "'";
}
$q .= implode(',',$qtmp) . $qend;
mysql_query($q);
}
}
/*
//renaming file
$filename2 = ("UploadedMatch.csv" . '.old');
rename("UploadedMatch.csv", $filename2);
/* Closing connection */
mysql_close($ASN);
?>