[PHP-DB] if and while writing to a txt file! From: Fredrik Arild Takle (ftakle <email protected>)
Date: 07/14/00

Hi there!

I'm currently making a phtml page that writes to a .txt file
Registering books and empl_no, like this:
bookno empl_no empl_no ....
1 55555 22222
2 55555 44444 78965

I want:
1. If the book exist in the txt file I want the empl_no added at the end.
2. If the book don't exist in the txt file I want the bookno and empl_no added on a new line.

This is my source:
<?
        $filnavn = "liste.txt";
        $fpr = fopen($filnavn, "r");
         $funnet = false;
            $nyfilnavn = "nyliste.txt";
        $nyfpr = fopen($nyfilnavn, "w+");
      while($innhold = fgets($fpr, 4096)) {
      $do_explode = explode(" ", $innhold);
 // Book exist add empl_no at end
          if ($do_explode[0] == $no) {
             $funnet = true;
        $count = count($do_explode) - 1;
        fwrite ($nyfpr, $innhold . " " . $empl_nr);
      }
          fwrite ($nyfpr, $innhold);
          echo "skriver gammelt";
      }

// Book don't exist add it!

         if ($funnet == false) {
        echo "Du er nå satt på ventelisten";
          fwrite ($nyfpr, "\n$no $empl_nr");
      }
      copy($nyfilnavn, $filnavn);
      chmod ($filnavn, 0755);
      fclose ($nyfpr);
?>

Is it best to write the information to a temp file?
I've done something wrong here because it don't seem to work!

I also have a problem executing chmod 777, it says permission denied!

Do I have to execute chmod when copying a file?

ANY SUGGESTIONS IMPROVEMENTS?!

Please write back!

------------------
Best Regards
Fredrik Arild Takle
ftakle <email protected>

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-db-unsubscribe <email protected>
For additional commands, e-mail: php-db-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>