This error driving me crazy :(

Hi!

I making a PDF file, but get this error message:

PHP Fatal error:  Cannot redeclare class mPDF in C:\DWASFiles\Sites\AgressionTestMysql\VirtualDirectory0\site\wwwroot\mssql\Reports\MPDF\mpdf.php on line 67


<?php
include_once("../mpdf.php");
require_once('Connect_databse.php');

ini_set('memory_limit', '256M');

session_start();


$table3='Reportform';
$table4 = 'P_SHOW_Transactions';


//$mpdf=new mPDF('c');
$mpdf=new mPDF('win-1252', 'A4', 11, 'DejaVuSansCondensed', 15, 15, 15, 15, 8, 8);
$mpdf->mirrorMargins = 0; // Use different Odd/Even headers and footers and mirror margins
$mpdf->defaultheaderfontsize = 10; /* in pts */
$mpdf->use_kwt = true;
$mpdf->keep_table_proportions = true;
$mpdf->shrink_tables_to_fit=1;
$mpdf->debug = true;
$mpdf->defaultheaderfontstyle = B; /* blank, B, I, or BI */
$mpdf->defaultheaderline = 1; /* 1 to include line below header/above footer */
$mpdf->defaultfooterfontsize = 10; /* in pts */
$mpdf->defaultfooterfontstyle = B; /* blank, B, I, or BI */
$mpdf->defaultfooterline = 1; /* 1 to include line below header/above footer */
$mpdf->SetHeader('{DATE j-m-Y}||Agreppa Report');
$mpdf->SetFooter('Side:{PAGENO}'); /* defines footer for Odd and Even Pages - placed at Outer margin */
$mpdf->SetFooter(array(
'L' => array(
'content' => 'Text to go on the left',
'font-family' => 'sans-serif',
'font-style' => 'B', /* blank, B, I, or BI */
'font-size' => '10', /* in pts */
),
'C' => array(
'content' => '- {PAGENO} -',
'font-family' => 'serif',
'font-style' => 'BI',
'font-size' => '18', /* gives default */
),
'R' => array(
'content' => 'Printed @ {DATE j-m-Y H:m}',
'font-family' => 'monospace',
'font-style' => '',
'font-size' => '10',
),
'line' => 1, /* 1 to include line below header/above footer */
), 'E' /* defines footer for Even Pages */
);





$html = '
<html>
<head>
<meta charset="utf-8" />
<style>
table.testtabell
{
    border:1px solid #cccccc;
  border-collapse: collapse;
  font-family: Verdana;
  font-size: 20px;
  margin-right: 15px;
}
.rapport2_header
{
    background-color: #efefef;
    border:1px solid #cccccc;
  color:#cccccc;
  font-size: 15px;
  font-family: Verdana;
  border-collapse: collapse;
    box-shadow: none ! important;
  padding-left:10px;
  padding-top:10px;
}
.rapport1_del8
{
   border:1px solid #cccccc;
   border-collapse: collapse;
   box-shadow: none ! important;
   padding-left:10px;
   padding-top:10px;
   font-size:12px;
   color:#b2b3c3;
}

.rapport1_del9
{
   border:1px solid #cccccc;
   border-collapse: collapse;
   box-shadow: none ! important;
   padding-left:10px;
   padding-bottom:8px;
   font-size:12px;
   color:#b2b3c3;
}

.rapport1_del1
{
    background-color: #efefef;
    border:0px solid #cccccc;
  border-collapse: collapse;
    box-shadow: none ! important;
  padding-left:10px;
}
.rapport1_del2
{
   background-color: #f8f8f8;
   border-left:0px solid #cccccc;
   border-bottom:1px solid #cccccc;
   border-right:0px solid #cccccc;
   border-collapse: collapse;
   padding-left:10px;
}
.rapport_brukernavn
{
   background-color: #f8f8f8; 
   border-right:1px solid #cccccc;
   border-left:0px solid #cccccc;
   border-bottom:1px solid #cccccc;
   border-collapse: collapse;
   padding-right:10px;
   font-family: Verdana;
   font-size: 11px;
   color:#cccccc;
   text-align:right;
}
.blank_row_noborder {
  height: 20px !important;
  background-color: #FFFFFF;
}
.blank_row {
  height: 20px !important;
  background-color: #FFFFFF;
  border-bottom: 1px solid #cccccc; /* or whatever specific values you prefer */
}
.rapport1_del3
{
   background-color: #ffffff;
   font-size:12px;
    border:0px solid #cccccc;
   border-collapse: collapse;
   box-shadow: none ! important;
}
.rapport_image1
{
   background-color: #ffffff;
   border: none ! important;
   box-shadow: none ! important;
   padding-right:10px;
}
IMG.displayed {
    display: block;
    margin-left: auto;
    margin-right: auto }
</style>

</head>

<body>
';


$brukerID = $_GET["brukerID"];
$kundeid = $_GET["kundeid"];


echo "MERKE1";
die();


$sql = "SELECT * FROM {$table3} WHERE UserID={$brukerID} and Organisation={$kundeid}";
$resultraptmp = sqlsrv_query($conn,$sql); 

// Hent parametere som er valgt for utvalget til rapporten
while($row3 = sqlsrv_fetch_array($resultraptmp)){

      $datofra = $row3['Datefrom'];
      $datotil = $row3['Dateto'];
      $kontr = $row3['Controllername'];
      $brukere = $row3['Username'];
      $svarsp = $row3['Answer'];
      $vilkenrapport = $row3['Report'];
      $organisasjon = $row3['OrganisationName'];
      $antsider = $row3['Pages'];
      $rec_count = $row3['Numberrecords'];
      $antrader = $row3['NumRows'];
      $datobrukes = 1;
      $side = $row3['Page'];

} 

if ($vilkenrapport=="Enkel rapport"){    
$html .= '<table width="100%" align="left" class="testtabell">'; 
$html .= '<tr>';
$html .= '<th class="rapport2_header" height="40px" align="left">Kontroller</th>';
$html .= '<th class="rapport2_header" height="40px" align="left">Lokasjon</th>';
$html .= '<th class="rapport2_header" height="40px" align="left">Dato</th>';
$html .= '<th class="rapport2_header" height="40px" align="left">Spørsmål</th>';
$html .= '<th class="rapport2_header" height="40px" align="left">Svar</th>';
      
$html .= '</tr>';  
}  
     

$sql = "SELECT Name,ControlName,LocationID,Location,ControlID,Organisation,Question,Note,CreatedDate,Answer,UserID,IsScale,Object,TransactionID,Organisationname FROM {$table4}";


$sql = $sql." Where CreatedDate between '{$datofra}' AND '{$datotil}'";


$substr = "Alle kontrollere";
if (strpos($kontr, $substr) === false) {
  $sql = $sql." and ControlName='{$kontr}'";
}

$substr = "Alle brukere";
if (strpos($brukere, $substr) === false) {

  
  // Hent UserID    
   $tsql_callSP = "{call GET_UserID( ?, ?)}";
   $params = array( 
                 array($brukere, SQLSRV_PARAM_IN),
                 array($brID, SQLSRV_PARAM_INOUT)
               );

/* Execute the query. */
   $stmt3 = sqlsrv_query( $conn, $tsql_callSP, $params);
   if( $stmt3 === false )
   {
       echo "Error in executing statement 1.\n";
       die( print_r( sqlsrv_errors(), true));
   }
   else
   {sqlsrv_free_stmt( $stmt3);}


  $sql = $sql." and UserID='{$brID}'";
}

if ($svarsp=="Ja"){
  $sql = $sql." and Answer='Ja'";
}

if ($svarsp=="Nei"){
  $sql = $sql." and Answer='Nei'";
}

if ($svarsp=="Avvik"){
  $sql = $sql." and Answer='Avvik'";
}

if ($svarsp=="Scale"){
  $sql = $sql." and Answer<>'Ja' and Answer<>'Nei' and Answer<>'Avvik' ";
}
  
$sql = $sql." and Organisationname='{$organisasjon}'";

$sql = $sql." ORDER BY ControlID,CreatedDate";

$retval = sqlsrv_query($conn,$sql); 

if( $retval === false )
{
       echo "Error in executing statement 12.\n";
       die( print_r( sqlsrv_errors(), true));
}

$TMP_KID=0;
$forstekontroller = 1;
$TMP_LOK=0;
$farge1="#ffffff";
$farge2="#d9eefa";
$valgfarge="#ccc";
$byttfarge = 1;
$antrader=1;
$antraderMAX= 20;



while($row3 = sqlsrv_fetch_array($retval)){
   
   $kontrollernavn = $row3['ControlName'];
   $lokasjonnr = $row3['LocationID'];
   $K_ID = $row3['ControlID'];
   $kunde_ID = $row3['Organisation'];
   $lokasjonnavn = $row3['Location']; 
   $sporsmal = $row3['Question'];
   $kommentar = $row3['Note'];
   $transdato = $row3['Location'];
   $svar = $row3['Answer']; 
   $usID = $row3['UserID'];  
   $scaleant = $row3['IsScale'];
   $bilderef="";     // Midligtidig satt til blank
   $brukernavn= $row3['Name'];

if ($vilkenrapport=="Enkel rapport"){  
    
    
$html .= '<tr>';
                                                     
if ($byttfarge==1){
   $valgfarge=$farge2;
   $byttfarge=2;
}
else
{ 
   $byttfarge=1;
   $valgfarge=$farge1;
}   

$html .= '<td class="rapport1_del8" bgcolor=' . $valgfarge . ' align="left">' . $kontrollernavn . '</td>'; 
$html .= '<td class="rapport1_del8" bgcolor=' . $valgfarge . ' align="left">' . $lokasjonnavn .'</td>';
$html .= '<td class="rapport1_del8"  bgcolor=' . $valgfarge . ' align="left">'. $transdato .'</td>';
$html .= '<td class="rapport1_del8"  bgcolor=' . $valgfarge . ' align="left">'. $sporsmal .'</td>'; 
      
if($svar=="Ja"){ 
   $html .= '<td colspan="2" class="rapport1_del9"  bgcolor=' . $valgfarge . ' align="left">' . $svar . '<img class="bildeviser" src="../../../images/jasvar.png" alt="Smiley face"></td>';
}

if($svar=="Nei"){ 
   $html .= '<td class="rapport1_del9"  bgcolor=' . $valgfarge . ' align="left">' . $svar . '<img class="bildeviser" src="../../../images/neisvar.png" alt="Smiley face"></td>';
}

 if($svar<>"Ja" and $svar<>"Nei"){
   $html .= '<td class="rapport1_del9"  bgcolor=' . $valgfarge . ' align="left">' . $svar . '<img class="bildeviser" src="../../../images/scale.png" alt="Smiley face"></td>';
}


}    
     
if ($vilkenrapport=="Standard rapport"){   
   
   if ($forstekontroller==1)
    {
       $forstekontroller=0;
     $TMP_KID = $K_ID;
     $TMP_LOK = $lokasjonnr;
     
        $html .='<table width="100%" align="center" class="testtabell"  style="page-break-inside:avoid">'; 
    $html .='<tr>';
    $html .='<td class="rapport1_del1" height="40px" colspan="4">' . $kontrollernavn .'</td>';
    $html .='</tr>';
    $html .='<tr>';
      $html .='<td class="rapport1_del2" colspan="3" height="40px">' . $lokasjonnavn . '</td>';
        $html .='<td class="rapport_brukernavn" >' . $brukernavn .'</td>';      
      $html .='</tr>';

    }
  

  
   if ((($TMP_KID<>$K_ID) or ($TMP_LOK<>$lokasjonnr)) and $forstekontroller==2)
   {
      if ($TMP_KID<>$K_ID) {$TMP_KID = $K_ID;}
    if ($TMP_LOK<>$lokasjonnr) {$TMP_LOK = $lokasjonnr;}
        $html .='</table>';
        $html .='<table width="100%" align="center" class="testtabell" style="page-break-inside:avoid">'; 
    $html .='<tr>';
    $html .='<td class="rapport1_del1" colspan="4" height="40px">' . $kontrollernavn . '</td>';
    $html .='</tr>';
    $html .='<tr>';
      $html .='<td class="rapport1_del2" colspan="3" height="40px">' . $lokasjonnavn .'</td>';
    $html .='<td class="rapport_brukernavn">' . $brukernavn .'</td>';
      $html .='</tr>';   
  
   }
   
    $html .='<tr class="blank_row_noborder">';
    $html .='<td colspan="4"></td>';
    $html .='</tr>';  
  
  $html .='<tr>';  
  $html .='<td  class="rapport1_del3" align="right" valign="top" width="120px"> Sporsmål: </td>';
  $html .='<td class="rapport1_del3" valign="top" width="380px">' . $sporsmal . '</td>';
    
  if ($bilderef=="")
    { 
    $html .='<td class="rapport1_del3" valign="top"></td>';
      $html .='<td valign="top" class="rapport_image1" rowspan="4"><img src="../../../images/ingen.png" height="160" width="150px" /></td>';
  }
  else
  {
    $html .='<td class="rapport1_del3" valign="top"></td>'; 
    $html .='<td valign="top" class="rapport_image1" rowspan="4"><img src="../../../uploads/' . $bilderef .'" height="160" width="150px" /></td>';
    }
  $html .='</tr>';  
  $html .='<tr>';
  $html .='<td  class="rapport1_del3" align="right" valign="top" width="120px"> Dato: </td>'; 
  $html .='<td  class="rapport1_del3" valign="top" width="380px">' . $transdato .'</td>';
  $html .='<td class="rapport1_del3" valign="top"></td>';
  $html .='</tr>';
  
  $html .='<tr>'; 
  $html .='<td  class="rapport1_del3" align="right" valign="top" width="120px"> Svar:</td>'; 
     
      if (($svar=="Ja") or ($svar=="Nei"))
    { 
         $html .='<td  class="rapport1_del3" valign="top" width="380px">' . $svar .'</td>';
    
    }
    else {
    
       $html .='<td  class="rapport1_del3" valign="top" width="380px">' . $svar . ' av ' . $scaleant .'</td>';
     }
  $html .='<td class="rapport1_del3" valign="top"></td>'; 
  $html .='</tr>';
  
  $html .='<tr>'; 
  $html .='<td  class="rapport1_del3" align="right" valign="top" width="120px"> Kommentar:</td>'; 
  $html .='<td  class="rapport1_del3" valign="top" width="380px">' . $kommentar .'</td>';
  $html .='<td class="rapport1_del3" valign="top"></td>';
  $html .='</tr>'; 
  
  $html .='<tr class="blank_row">';
    $html .='<td colspan="4"></td>';
    $html .='</tr>';  
   
   $forstekontroller=2;
}}

$html .= '</table>';
$html .= '</body>';
$html .= '</html>';

echo $html;
die();

$mpdf->SetDisplayMode('fullpage');

$mpdf->list_indent_first_level = 0; // 1 or 0 - whether to indent the first level of a list
$mpdf->WriteHTML($html);

$mpdf->Output();
exit;

?>

Open in new window



I dont know why this is happening ?????
LVL 2
team2005Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Surranoapplication managerCommented:
Perhaps if you could include mpdf.php as well...
but
have you tried "require_once" instead of "include_once"?
team2005Author Commented:
Hi!

Dident work ?

Try to include the mpdf.php, but i cant ?
Maby to big ?
Surranoapplication managerCommented:
Can you post the first 70 lines of mpdf.php? Error should be on line 67...
Get Blueprints for Increased Customer Retention

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

team2005Author Commented:
Hi!

<?php

// ******************************************************************************
// Software: mPDF, Unicode-HTML Free PDF generator                              *
// Version:  5.7     based on                                                   *
//           FPDF by Olivier PLATHEY                                            *
//           HTML2FPDF by Renato Coelho                                         *
// Date:     2013-07-14                                                         *
// Author:   Ian Back <ianb@bpm1.com>                                           *
// License:  GPL                                                                *
//                                                                              *
// Changes:  See changelog.txt                                                  *
// ******************************************************************************


define('mPDF_VERSION','5.7');

//Scale factor
define('_MPDFK', (72/25.4));

/*-- HTML-CSS --*/
define('AUTOFONT_CJK',1);
define('AUTOFONT_THAIVIET',2);
define('AUTOFONT_RTL',4);
define('AUTOFONT_INDIC',8);
define('AUTOFONT_ALL',15);

define('_BORDER_ALL',15);
define('_BORDER_TOP',8);
define('_BORDER_RIGHT',4);
define('_BORDER_BOTTOM',2);
define('_BORDER_LEFT',1);
/*-- END HTML-CSS --*/

if (!defined('_MPDF_PATH')) define('_MPDF_PATH', dirname(preg_replace('/\\\\/','/',__FILE__)) . '/');
if (!defined('_MPDF_URI')) define('_MPDF_URI',_MPDF_PATH);

require_once(_MPDF_PATH.'includes/functions.php');
require_once(_MPDF_PATH.'config_cp.php');

if (!defined('_JPGRAPH_PATH')) define("_JPGRAPH_PATH", _MPDF_PATH.'jpgraph/'); 

if (!defined('_MPDF_TEMP_PATH')) define("_MPDF_TEMP_PATH", _MPDF_PATH.'tmp/');

if (!defined('_MPDF_TTFONTPATH')) { define('_MPDF_TTFONTPATH',_MPDF_PATH.'ttfonts/'); }
if (!defined('_MPDF_TTFONTDATAPATH')) { define('_MPDF_TTFONTDATAPATH',_MPDF_PATH.'ttfontdata/'); }

$errorlevel=error_reporting();
$errorlevel=error_reporting($errorlevel & ~E_NOTICE);

//error_reporting(E_ALL);

if(function_exists("date_default_timezone_set")) {
	if (ini_get("date.timezone")=="") { date_default_timezone_set("Europe/London"); }
}
if (!function_exists("mb_strlen")) { die("Error - mPDF requires mb_string functions. Ensure that PHP is compiled with php_mbstring.dll enabled."); }

if (!defined('PHP_VERSION_ID')) {
    $version = explode('.', PHP_VERSION);
    define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
}
// Machine dependent number of bytes used to pack "double" into binary (used in cacheTables)
$test = pack("d", 134455.474557333333666);
define("_DSIZE", strlen($test));

class mPDF
{

///////////////////////////////
// EXTERNAL (PUBLIC) VARIABLES
// Define these in config.php
///////////////////////////////

Open in new window

Surranoapplication managerCommented:
Well it looks ok for me.
I definitely think that there's another include or require in the recursive set of included files that is not *_once and still includes this file. Maybe if you add the error_reporting *before* this include_once line then we'll see some useful warnings.

<?php
$old_er = error_reporting(63);
include_once("../mpdf.php");
require_once('Connect_databse.php');
error_reporting($old_er);
...

Open in new window

team2005Author Commented:
Hi!

Only get a blank page ???
Surranoapplication managerCommented:
??? without error_reporting set to max you get an error but if you set it to max you get an empty page and no errors, not even warnings? I certainly assume you left the remainder of the file in place...
Ray PaseurCommented:
PHP Fatal error:  Cannot redeclare class says that somewhere in the program (script) text you have a second statement that uses the Class keyword to define the class named MPDF.  Class names are like function names - case-insensitive.  You can only have one class of each name in the script file.
<?php // RAY_temp_team2005.php
error_reporting(E_ALL);

class foo {}
class foo {} // FATAL ERROR HERE

Open in new window

The script file will include not only the script you execute, but any other scripts brought in by include().

The usual approach to an issue like this one is to use a code scanner, like the TextPad "find in files" function, to search the source library for instances of 'MPDF.'

Where did you get the template that you're starting from?  The reason I ask is this set of instructions.  That looks technically incompetent to me and I would avoid depending on anything that could not be run with error_reporting(E_ALL)!!
$errorlevel=error_reporting();
$errorlevel=error_reporting($errorlevel & ~E_NOTICE);

//error_reporting(E_ALL);

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
team2005Author Commented:
Hi!

Changed som names for database connections, and now i get this error message:

Output has already been sent from the script - PDF file generation aborted.
Ray PaseurCommented:
Hi, team2005.  It looks like the errors are all over the map, and that makes it very, very difficult to get good results.  If I were dealing with this application, I would start over and reduce it to the SSCCE, which is the minimum kind of "Hello World" example that proves you have the scripts in the right places, and the MPDF script can produce a usable PDF file.

Once you have that part working, begin adding additional functionality one step at a time, testing each addition.  When something "breaks" you will know that it was caused by the last incremental addition, and you can debug that small part of the application, instead of wondering where things are going wrong.  By doing this step-by-step you will get accurate results much faster than if you try to do it all at once, I promise!
Surranoapplication managerCommented:
This latter part may be caused by some premature input. Some functions like session_start() expect that nothing (no debug echos, no error messages, nothing) had been echoed previously. There must be some similar restriction in mPDF as well, so comment the high error_reporting settings and the debug lines (e.g. echo "MERKE1";)
team2005Author Commented:
Hi!

Fixed the error now, i just renamed som variables for database-file.

Then everything works fine :)

Probebly som issue about conflict with som classes in MPDF-file ?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.