mcdhappy80 0 Newbie Poster

Hi. This is my first topic on this forum and I hope I'm posting in the right place.

I have a need to generate three different (yet similar), RTF based Template, reports.
I have successfully created 2 out of three. On the problematic third I cannot make the script change (via the str_replace() function) two placeholder fields, even though database fetches the results successfully. The only difference between the reports is that the third has the most placeholder fields.
Here's the code:

<?php

   session_start();
   
   //if($_SESSION['auth'] == "yes")
   //{
      include("simple_encryption.php");
      
      //create short variable names
      //$name = $_POST['name'];
      //$score = $_POST['score'];
      //$otp_id = decrypt($_SESSION['otp_id']);
      //echo $otp_id;
      $u_id = decrypt($_SESSION['otp_id']);
      //echo $u_id;
      //exit();
      
      // check we have the parameters we need
      if(!$u_id) 
      {
         echo "<h1>Error:</h1>
         <p>This page was called incorrectly</p>";
      } 
      else
      {
         /*$brsrvs = decrypt($_POST['id']);
         echo $brsrvs;
         echo "<hr/>";*/
         //exit();
         
         include("dbstuff.inc.php");
         
         $cnx = mysqli_connect($host,$user,$password,$database) or die("Query died: Konekcija");
         
         if(!$cnx)
         {
            echo "Konekcija neuspesna";
            exit();
         }
         
         $sql = "SELECT BrSrvs, Korisnik, Uredjaj, DanPrijema, ServiserPrijem, OpisKvara, Uradjeno, DanObavestavanja, ServiserRadio, ServiserPredao, DATEDIFF(DanObavestavanja,DanPrijema) AS ZavrsenoZa FROM srvs WHERE BrSrvs='$u_id'";
         
         //echo $sql;
         
         $result = mysqli_query($cnx, $sql);
         
         if(!$result)
         {
            echo "Konekcija neuspesna<br/>". mysqli_errno($cnx) . "<br/>" . mysqli_error($cnx);
         }
         
         $result = mysqli_query($cnx, $sql) or die("Query died: SQL Upit 1");
         $result = mysqli_query($cnx, $sql);
         
         if(!$result)
         {
            echo "Br:" . mysqli_errno($cnx) . "<br/>Opis:" . mysqli_error($cnx) . "<br/>";
         }
         //echo $result;
         //$rows = mysqli_num_rows($result);
         
         while($row = mysqli_fetch_array($result))
         {
           
           $brsrvs = $row['BrSrvs'];
           //echo $brsrvs;
           $korisnik = $row['Korisnik'];
           $uredjaj = $row['Uredjaj'];
           $dan_prijema = $row['DanPrijema'];
           $serviser_prijem = $row['ServiserPrijem'];
           $opis_kvara = $row['OpisKvara'];
           //echo $opis_kvara;
           //exit();
           $uradjeno = $row['Uradjeno'];
           $dan_obavestavanja = $row['DanObavestavanja'];
           $serviser_radio = $row['ServiserRadio'];
           $serviser_predao = $row['ServiserPredao']; 
           $zavrseno_za = $row['ZavrsenoZa']; 
           //echo $zavrseno_za;
           //exit();
         }
         
         mysqli_close($cnx);
         
         //generate the headers to help a browser choose the correct application
         header('Content-type: application/msword');
         header('Content-Disposition: inline, filename=rtf/izlaz.rtf');
         $date = date('F d, Y');
         
         // open our template file
         $filename = 'rtf/izlaz.rtf';
         $fp = fopen ($filename, 'r');
         
         //read our template into a variable
         $output = fread( $fp, filesize($filename));
         fclose ($fp);
         
         $datum_vreme = date("Y-m-d H:m:s");
         //$zavrseno_za = "";   // Treba da se racuna razlika u datumima DanPrijema i DanObavestavanja

         $output = str_replace('<<opiskvara>>', strtoupper($opis_kvara), $output);
         $output = str_replace('<<datum_vreme>>', strtoupper($datum_vreme), $output);
         $output = str_replace('<<brsrvs>>', strtoupper($u_id), $output);
         $output = str_replace('<<korisnik>>', strtoupper($korisnik), $output);
         $output = str_replace('<<uredjaj>>', strtoupper($uredjaj), $output);
         $output = str_replace('<<dan_prijema>>', strtoupper($dan_prijema), $output);
         $output = str_replace('<<uradjeno>>', strtoupper($uradjeno), $output);
         $output = str_replace('<<serviser_radio>>', strtoupper($serviser_radio), $output);
         $output = str_replace('<<dan_obavestavanja>>', strtoupper($dan_obavestavanja), $output);
         $output = str_replace('<<zavrseno_za>>', strtoupper($zavrseno_za), $output);
         $output = str_replace('<<serviser_predao>>', strtoupper($serviser_predao), $output);
         $output = str_replace('<<serviserprijem>>', strtoupper($serviser_prijem), $output);

         // send the generated document to the browser
         echo $output;
      }
   /*}
   else
   {
      //echo "Nemate dozvolu da gledate ovu stranicu";
      header("Location: login.php");
      exit();
   }*/
?>

Does anyone know what ca be the issue here?
Thank You.