Page 1 of 1

inserting data from text file to DB

Posted: Mon Jul 08, 2002 12:24 pm
by scrtagt69
I have the following code to read in a text file I have:

Code: Select all

$fd = fopen ("d:active.txt", "r");
while (!feof ($fd)) {
    $line= fgets($fd, 4096);
}
fclose ($fd);

$MyArray=explode("|", $line);
$fd = fopen ("d:active.txt", "r");
while (!feof ($fd)) {
      $line= fgets($fd, 4096);

      $MyArray=explode("|", $line);
      $LastName=addslashes($MyArrayї0]);
      $FirstName=addslashes($MyArrayї1]);
      $MiddleName=$MyArrayї2];
      $SSN=$MyArrayї3];
    $HireDate=$MyArrayї4];
    $Jobcode=$MyArrayї5];
    $WorkPhone=$MyArrayї6];
    $JobTitle=addslashes($MyArrayї7]);
    $MailCode=$MyArrayї8];
    $Department=addslashes($MyArrayї9]);
    $Birthdate=$MyArrayї10];
    $Email=$MyArrayї11];
    $Termination=$MyArrayї12];

I have a Departments table with the fields of Dptkey,Shortname, and Code (Same as MailCode from above text file) and an ActiveEmployees table. What I need to do though is fill in the ActiveEmployees table with the above data, and reference the Departments table to pull out the Dptkey to insert that into the ActiveEmployees table. The way I reference that table, is through the MailCode from the text file. That mail code matches the Departments MailCode field which in return should pull the Dptkey. I hope this makes sense. So i wrote the below code to try and accomplish this, but i get an undefined index error.:

Code: Select all

$SQL3="SELECT * FROM Departments";
$Result3=mysql_query($SQL3) OR DIE mysql_error());
    
while ($rows=mysql_fetch_array($Result3))
    {
$dptkey    = $rowsї"Dptkey"];
$shortname = $rowsї"Shortname"];
$code      = $rowsї"Code"];
$dptnameї"$code"] = $shortname;
$dptreckeyї"$code"] = $dptkey;
}

$empdpname = $dptnameї"$MailCode"];
$empdpkey = $dptreckeyї"$MailCode"];

This is the error:
Warning: Undefined index: 00582 on line 68
Warning: Undefined index: 00582 on line 69

the 00582 is the MailCode from the text file..and this error repeats for each record till it loops through all the records. Line 68 and line 69 are the last 2 lines of the above PHP code. I need the Dptkey there not the MailCode. Any ideas what im doing wrong...or any other ways to do what im trying to do....im stuck........

Oh yeah...all the data does get inserted..its just the Dptkey that does not fill in.