Hi.
I simplified my problem, but if you guys can help me solve this I can use it in my script.
English isnt my language, if someone can help me but didnt understand 100% what I wrote, please tell me what it wasnt clear.
I have a big text file that has the following format:
Files in C:\bla\bla\
filename1.txt
filename2.txt
.
.
filenameN.txt
Files in C:\bla\bla2\
filename-a.txt
filename-b.txt
.
.
filename-Z.txt
and repeats over and over...
I wanted to do a table: "folders" (dir_id, dir_name)
and a table called "files" (dir_id, file_name)
In order to do this I wrote:
while (!feof($fp)) // $fp is the file I opened before
{
$line= fgets($fp, 100);
if (substr($line,0,9)=="Files in ")
{
$newdir = substr($line,9);
$query2 = "insert into folders values
(NULL, '".addslashes($newdir)."');";
$result2 = mysql_query($query2);
$newdirid = mysql_insert_id();
}
else { // the line has a filename
$query3 = "insert into files values ( $newdirid, '".addslashes($line)."'):";
$result3 = mysql_query($query3);
}
fclose($fp);
This script will run, if the $line has information about the "folder" it will insert it in 'Folders' table and will store the LAST ID in $newdirid.
If the $line has information about a filename it will store the name ( $line ) and the folder's ID where it is stored, that is the last folder inserted, so it should use $newdirid.
I'm getting $newdirid correctly, but when I use it on $query3, $newdirid is empty.
Any hints on what Im doing wrong ?
Thanks in advance.