-2

What's the error in below code: I'm getting the error as below:

PHP Parse error: syntax error, unexpected T_STRING in pdf_test_question_paper.php on line 38

$header_html = '<table border="0" width="100%" cellpadding="0" cellspacing="0" style="font-size:12px; font-family:verdana;">
<tr>
  <td><img src="http://www.example.com/upload_media/coaching/logo/display/".$coaching_details['coach_inst_logo_name']." width="198"></td>
  <td>
    <h2 style="margin:0;padding:0;">Jumbo Exam Easing your Exam Preparation</h2>
    <span>$coaching_address</span>
  </td>
</tr>
<tr><td colspan="2"><hr style="background-color: #000000;height:1px;border:1px;"/></td></tr>
</table>';

Any help would be greatly appreciated.

PHPLover
  • 1
  • 51
  • 158
  • 311
  • 1
    http://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them – Steven V Nov 18 '13 at 16:20
  • 2
    What's line 38? I see too many questions like this. Take the time to learn how to [interpret errors and fix your code](http://jason.pureconcepts.net/2013/05/fixing-php-errors/). – Jason McCreary Nov 18 '13 at 16:21

3 Answers3

2

When you wrap your string in single quotes, you're using literal values. That means $coaching_address will never be evaluated. You should use a heredoc instead for this amount of code:

$header_html = <<<EOD
<table border="0" width="100%" cellpadding="0" cellspacing="0" style="font-size:12px; font-family:verdana;">
<tr>
  <td><img src="http://www.xyz.com/upload_media/coaching/logo/display/$coaching_details['coach_inst_logo_name']" width="198"></td>
  <td>
    <h2 style="margin:0;padding:0;">Zimma Exam Easing your Exam Preparation</h2>
    <span>$coaching_address</span>
  </td>
</tr>
<tr><td colspan="2"><hr style="background-color: #000000;height:1px;border:1px;"/></td></tr>
</table>
EOD;
Kermit
  • 33,827
  • 13
  • 85
  • 121
0

please use the correct quotation in case of string concaternation:

$header_html = '<table border="0" width="100%" cellpadding="0" cellspacing="0" style="font-size:12px; font-family:verdana;">
<tr>
  <td><img src="http://www.example.com/upload_media/coaching/logo/display/'.$coaching_details['coach_inst_logo_name'].' width="198"></td>
  <td>
    <h2 style="margin:0;padding:0;">Jumbo Easing your Exam Preparation</h2>
    <span>'.$coaching_address.'</span>
  </td>
</tr>
<tr><td colspan="2"><hr style="background-color: #000000;height:1px;border:1px;"/></td></tr>
</table>';
PHPLover
  • 1
  • 51
  • 158
  • 311
steven
  • 4,868
  • 2
  • 28
  • 58
  • just note there is a second variable in the code: $coaching_address For completness, this should be taken out of quotes as well. – Liam Wiltshire Nov 18 '13 at 16:21
0

You start your string using single quotes, however you are trying to break out of the quotes using a double quote.

The correct code is:

$header_html = '<table border="0" width="100%" cellpadding="0" cellspacing="0" style="font-size:12px; font-family:verdana;">
<tr>
  <td><img src="http://www.example.com/upload_media/coaching/logo/display/'.$coaching_details['coach_inst_logo_name'].' width="198"></td>
  <td>
    <h2 style="margin:0;padding:0;">Jumbo Easing your Exam Preparation</h2>
    <span>'.$coaching_address.'</span>
  </td>
</tr>
<tr><td colspan="2"><hr style="background-color: #000000;height:1px;border:1px;"/></td></tr>
</table>';
PHPLover
  • 1
  • 51
  • 158
  • 311
Liam Wiltshire
  • 1,254
  • 13
  • 26