-2

I have a file in new_pm.php contains code like this:

<?php include 'box_right.php';?>

then, in the box_right.php contains code like this:

<?php
echo "<div class="box_right">
        <a href="list_pm.php">Pesan(<?php echo $nb_new_pm; ?>)</a> - <a href="profile.php?id=<?php echo $_SESSION['userid']; ?>"><?php echo htmlentities($_SESSION['username'], ENT_QUOTES, 'UTF-8'); ?></a> (<a href="logout.php">Logout</a>)
    </div>";
?>

However, a warning like this:

Parse error: syntax error ....

How do I resolve this?

edit:

<?php
echo "<div class='box_right'>
        <a href='list_pm.php'>Pesan(<?php echo $nb_new_pm; ?>)</a> - <a href='profile.php?id=<?php echo $_SESSION['userid']; ?>'><?php echo htmlentities($_SESSION['username'], ENT_QUOTES, 'UTF-8'); ?></a> (<a href='logout.php'>Logout</a>)
    </div>";
?>
Sigit Purnomo
  • 11
  • 1
  • 7

2 Answers2

0

Either escape the double quotes within the string, or change the quotes around the string to single quotes.

Also remove the second set of php tags.

ajon
  • 7,868
  • 11
  • 48
  • 86
0

Replace your PHP block with this code:

<?php
echo '<div class="box_right">
        <a href="list_pm.php">Pesan(' . $nb_new_pm . ')</a> - <a href="profile.php?id=' . $_SESSION['userid'] .'">' . htmlentities($_SESSION['username'], ENT_QUOTES, 'UTF-8') . '</a> (<a href="logout.php">Logout</a>)
    </div>';
?>
Saqib Amin
  • 1,171
  • 7
  • 16