Page 1 of 1

What's wrong ?

Posted: Mon Jul 11, 2005 7:02 am
by pookie62
Hi,
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);
?>

Posted: Mon Jul 11, 2005 7:05 am
by Dale
Is this suppose to have 2 dollar signs?

Code: Select all

$qtmp[] = "$columnname = '$$columnname'";
Fixed:

Code: Select all

$qtmp[] = "$columnname = '$columnname'";

Posted: Mon Jul 11, 2005 7:30 am
by pookie62
Hi Dale,
Thanks for your reply, I changed it, but still nothing happens..
I found this script somewhere and don't know why there are two $$'s.
The script is supposed to compare the data in the csv file with the table, then update or insert into table.

How would you do this ?

Posted: Mon Jul 11, 2005 8:01 am
by onion2k
Two dollar signs means it's a reference, and it definitely is supposed to be there.

Two questions though:

1. explode(';',$csv[$x]) .. .csv files usually use comma rather than semi-colon as a seperater. That seems odd. Is it right?

2. Does your database table match the expected columns in this CSV exactly?

Are there really no errors? Have you checked your error log?

Posted: Mon Jul 11, 2005 8:05 am
by Dale
onion2k wrote:Two dollar signs means it's a reference, and it definitely is supposed to be there.
Ahhh, i'll remember that for the future. Thanks.

Posted: Mon Jul 11, 2005 8:08 am
by pookie62
Onion2k,
This is the first line form the csv file:
Id;Naam;Voornaam;ASNNR;Datum_lid;URL;Vereniging;Adres;Postcode;Woonplaats;Telnr;Email;Oud_Sefnr
So, yes the seperator is indeed the semicolon.

This is the structure of the table:

Id bigint(20) Nee auto_increment
Naam varchar(255) Ja NULL
Voornaam varchar(255) Ja NULL
ASNNR bigint(20) Ja NULL
Datum_lid datetime Ja NULL
URL varchar(255) Ja NULL
Vereniging varchar(255) Ja NULL
Adres varchar(255) Ja NULL
Postcode varchar(255) Ja NULL
Woonplaats varchar(255) Ja NULL
Telnr varchar(255) Ja NULL
Email varchar(255) Ja NULL
Oud_Sefnr varchar(255) Ja NULL
Where should I fine the errorlog ??
Hosted website.. so I can't access everything.
Hopes this helps..

Posted: Mon Jul 11, 2005 10:55 am
by s.dot
the error log should be in the same directory where that contains the script

also, make sure that your .CSV file resides in the same directory as well.

Posted: Mon Jul 11, 2005 11:32 am
by pookie62
the error log should be in the same directory where that contains the script
There is nothing that looks like a errorlog..
also, make sure that your .CSV file resides in the same directory as well.
Yep, it is