I have html form, upon click on submit button, i am trying to create pdf report by using dom pdf. everything is working fine but for loop section creating issue. can i have help from this prestigious forum to fix this issue ?? here is my code to convert post values of form into pdf with dompdf
its not displaying pdf and gave following error Parse error : syntax error, unexpected âservpronameâ (T_STRING), expecting â,â or â)â in C:\xampp\htdocs\abc\Invoice.php on line 103
Itâs a quoting issue, surely? You havenât closed the string that you open for the call to loadHTML() before you open a new PHP tag and try to run a for() loop. Or do you intend that the raw PHP code will be inside your string?
No, itâs because you donât close the quotes before trying to execute some more PHP. I donât know anything about loadHTML(), but I canât imagine it will execute PHP code inside the string youâre sending it, that sounds like a terrible security flaw if it does. (ETA - if itâs the one on Github, it doesnât execute the code.)
To clarify, this line:
<table class="center" border=1 width=600>
should have a closing single-quote and a semi-colon on the end. I also prefer to see consistency in code - if youâre surrounding the class-name with double-quotes, do the same for the border and width parameters.
Inside your loop, do you actually want to echo those values, or do you want to add them onto the end of the string that you pass into loadHTML()? If the latter, youâd be better building up the string in a variable, and then calling loadHTML() at the end of your code when it contains everything.
$content = " All the stuff you have in your string before the for-loop starts"
for ($i=0;$i<count($_POST['servproname']);$i++) {
$content .= "each HTML table row that you currently echo";
}
$content .= "</table>";
$dompdf->loadHtml($content);
... and then the rest of your code