Home » Php » Getting error when generating PDF using TCDPF but works perfectly when echoed in a page

Getting error when generating PDF using TCDPF but works perfectly when echoed in a page

Posted by: admin October 26, 2017 Leave a comment

Questions:

i have problem generating pdf using TCPDF.
i am viewing the same code on a page, and using the same method to generate,
the following error occurs when i need to display the hotel booking details,
if i am eliminating the hotels booking details, the pdf is generated successfully, but when i am writing the code again to show the hotel details, it gives an error
here are the two link for the details

  1. 1) For View purpose view Package
  2. PDF Generating without hotel detials Without hotel details
  3. PDF Generating with hotel details with hotel details

this is error it get. when i am generating pdf with hotel detials
Warning: array_push() expects parameter 1 to be array, null given in /home/ankitd5/public_html/b2b/includes/tcpdf/tcpdf.php on line 16918

Warning: array_push() expects parameter 1 to be array, null given in /home/ankitd5/public_html/b2b/includes/tcpdf/tcpdf.php on line 16918

Warning: array_push() expects parameter 1 to be array, null given in /home/ankitd5/public_html/b2b/includes/tcpdf/tcpdf.php on line 16918

Warning: array_push() expects parameter 1 to be array, null given in /home/ankitd5/public_html/b2b/includes/tcpdf/tcpdf.php on line 16918

Warning: array_push() expects parameter 1 to be array, null given in /home/ankitd5/public_html/b2b/includes/tcpdf/tcpdf.php on line 16918

Warning: array_push() expects parameter 1 to be array, null given in /home/ankitd5/public_html/b2b/includes/tcpdf/tcpdf.php on line 16918

Warning: array_push() expects parameter 1 to be array, null given in /home/ankitd5/public_html/b2b/includes/tcpdf/tcpdf.php on line 16918

Warning: array_push() expects parameter 1 to be array, null given in /home/ankitd5/public_html/b2b/includes/tcpdf/tcpdf.php on line 16918

Warning: array_push() expects parameter 1 to be array, null given in /home/ankitd5/public_html/b2b/includes/tcpdf/tcpdf.php on line 16918

Warning: array_push() expects parameter 1 to be array, null given in /home/ankitd5/public_html/b2b/includes/tcpdf/tcpdf.php on line 16918

Warning: array_push() expects parameter 1 to be array, null given in /home/ankitd5/public_html/b2b/includes/tcpdf/tcpdf.php on line 16918

Warning: array_push() expects parameter 1 to be array, null given in /home/ankitd5/public_html/b2b/includes/tcpdf/tcpdf.php on line 16918

Warning: Invalid argument supplied for foreach() in /home/ankitd5/public_html/b2b/includes/tcpdf/tcpdf.php on line 19478

Warning: Invalid argument supplied for foreach() in /home/ankitd5/public_html/b2b/includes/tcpdf/tcpdf.php on line 19510

Warning: Cannot modify header information – headers already sent by (output started at /home/ankitd5/public_html/b2b/includes/tcpdf/tcpdf.php:16918) in /home/ankitd5/public_html/b2b/includes/tcpdf/tcpdf.php on line 7624
TCPDF ERROR: Some data has already been output to browser, can’t send PDF file

here is my code.
//for view the details

<table class='mytable'>
<?php
if(isset($_GET['packid']))
{
$id=$_GET['packid'];
$queryagent= mysqli_query($mysqli,"SELECT * FROM rmt_bookings where b_id='$id'");

while($rs=mysqli_fetch_array($queryagent)){

echo "<tr><td>Client Name</td><td colspan='3'> ".$rs['b_cname']."</td></tr>
<tr><td>Client Address</td><td colspan='3'> ".$rs['b_caddress']."</td></tr>
<tr><td>Client Phone</td><td colspan='3'> ".$rs['b_cphone']."</td></tr>
<tr><td>Client Email</td><td colspan='3'> ".$rs['b_cemail']."</td></tr>
<tr><td>No of Persons</td><td>No of Adults : ".$rs['b_cadult']."</td>
<td>No of Child : ".$rs['b_cchild']."</td>
<td>No of Infants : ".$rs['b_cinfant']."</td></tr>
<tr><td>Package Name</td><td colspan='3'> ".$rs['b_pname']."</td></tr>
<tr><td>Tour Location</td><td colspan='3'> ".$rs['b_location']."</td></tr>
<tr><td>Depature Date</td><td colspan='3'> ".$rs['b_date']."</td></tr>
";
$b_destinations = unserialize( base64_decode( $rs['b_destinations'] ) );
$b_nights = unserialize( base64_decode( $rs['b_nights'] ) );

foreach (array_combine($b_destinations[0], $b_nights[0]) as $desti=>$nights)
{
echo"
<tr><td>Detination</td><td colspan='2'> ".$desti."</td><td>Nights : ".$nights."</td></tr>";
}

echo "<tr><td colspan='4'><h4>Hotel details</h4></td></tr>";

//hotel detail starts here
$b_hdest = unserialize($rs['b_hdest']);
$b_hname = unserialize($rs['b_hname']);
$b_hadd = unserialize($rs['b_hadd'] );
$b_hphone = unserialize($rs['b_hphone']);
$b_hin = unserialize($rs['b_hin']);
$b_hout = unserialize( $rs['b_hout']);
$b_hroom = unserialize( $rs['b_hroom'] );
$b_hmeal = unserialize( $rs['b_hmeal'] );
$b_haextra = unserialize( $rs['b_haextra'] );
$b_hcextra = unserialize( $rs['b_hcextra'] );
$b_hspecial = unserialize( $rs['b_hspecial'] );
$b_hincl = unserialize( $rs['b_hincl'] );


for($i=0;$i<count($b_hdest[0]);$i++){
    echo"
        <tr><td colspan='4'>Hotel Details ".($i+1)."</td></tr>
        <tr><td>Location : ".$b_hdest[0][$i]."</td><td>Name : ".$b_hname[0][$i]."</td><td>Address : ".$b_hadd[0][$i]."</td><td>Phone : ".$b_hphone[0][$i]."</td><tr>
        <tr><td>CheckIn : ".$b_hin[0][$i]."</td><td>CheckOut : ".$b_hout[0][$i]."</td><td>Rooms : ".$b_hroom[0][$i]."</td><td>Meals : ".$b_hmeal[0][$i]."</td><tr>
        <tr><td>Extra Adult : ".$b_haextra[0][$i]."</td><td>Extra Child : ".$b_hcextra[0][$i]."</td><td>Special : ".$b_hspecial[0][$i]."</td><td>Inclusion : ".$b_hincl[0][$i]."</td><tr>
    ";
}

//hotel details ends here

$titledata = unserialize( base64_decode( $rs['b_it_title'] ) );
$detaildata = unserialize( base64_decode( $rs['b_it_detail'] ) );
$daycnt=1;
echo "<tr><td colspan='4'><h4>Itinerary Details</h4></td></tr>
<tr><td><b>Day</b></td><td><b>Title</b></td><td colspan='2'><b>Details</b></td></tr>";
foreach (array_combine($titledata[0], $detaildata[0]) as $title=>$detail)
{
echo"<tr><td>Day : ".$daycnt."</td><td>".$title."</td><td colspan='2'>".nl2br($detail)."</td></tr>";
$daycnt++;
}

echo"<tr><td><b>What You Get</b></td><td><b>Exclusion</b></td><td><b>Places of Intrest</b></td><td></td></tr>
<tr><td>".nl2br($rs['b_incl'])."</td><td>".nl2br($rs['b_excl'])."</td><td>".nl2br($rs['b_other'])."</td><td></td></tr>";
}
}
?>
Answers: