Error while converting phphtml form into pdf using dompdf

i am trying to convert my PHP/HTML form into pdf by using dompdf after clicking submit button. Everything was working fine but when I used for loop then following error occurred :

Parse error: syntax error, unexpected ‘servproname’ (T_STRING), expecting ‘,’ or ‘)’ in C:\xampp\htdocs\abc\invoice.php

here is my code :

          <?php
namespace Dompdf;
require_once 'dompdf/autoload.inc.php';

if(isset($_POST['submit']))
{
$dompdf = new Dompdf(); 
$dompdf->loadHtml('
<html>
 for ($i=0;$i<count($_POST['servproname']);$i++) {
 <tr>
<td style = "text-align:left; border:1px solid #cccccc;">'.$_POST['servproname'][$i].'</td>   
<td style = "text-align:left; border:1px solid #cccccc;">'.$_POST['docname'][$i].'</td>
<td style = "text-align:center; border:1px solid #cccccc;">'.$_POST['price1'][$i].'</td>
<td style = "text-align:center; border:1px solid #cccccc;">'.$_POST['qty'][$i].'</td>
<td style = "text-align:center; border:1px solid #cccccc;">'.$_POST['tot4'][$i].'</td>
}
</table>
');
$dompdf->setPaper('A4', 'landscape');
$dompdf->render();
$dompdf->stream("",array("Attachment" => false));
exit(0);
}
?>

You are not starting a <table>
You are missing a closing </tr>

i make those chnages but error still exist when converting into pdf using dompdf

Your index name is in single-quotes, inside a string definition surrounded by single quotes. Surely that’s the cause of the error message? Can you stick a for-next loop inside a quoted string like that? I don’t know DomPDF, but it seems a very strange syntax.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.