Inserting php code within php code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
croniccoder
Forum Commoner
Posts: 27
Joined: Fri Jul 07, 2006 10:45 am

Inserting php code within php code

Post by croniccoder »

I am getting a parse error from the code snippet below:

Code: Select all

<?php
   if ($job_row['updatepostdate'] != NULL)
   {
         print "<td class="tdForm"><?php echo($job_row['updatepostdate'])?></td>";
   }
   else
   {
        print "<td class="tdForm"><?php echo($job_row['posted'])?></td>";
   }
?>
Specifically, in <?php echo($job_row['updatepostdate'])?>

What would be the correct way to insert php inside of php?[/b]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You need to escape your quotes and not try to use PHP inside of other PHP. Change this...

Code: Select all

print "<td class="tdForm"><?php echo($job_row['updatepostdate'])?></td>";
To this

Code: Select all

print '<td class="tdForm">' . $job_row['updatepostdate'] . '</td>';
croniccoder
Forum Commoner
Posts: 27
Joined: Fri Jul 07, 2006 10:45 am

Post by croniccoder »

Fantastic Everah!

Thanks for the help! :D
Post Reply