Jump to content
Fórum Script Brasil
  • 0

PHP dentro de echo


Question

Bom dia, estou fazendo um menu mas queria liberar por nivel de acesso, mas estou tendo erros para printar esse menu, se puderem me ajudar.

 

          <?php
          if($_SESSION['usr_id'] == 2){

          echo"<li class=\"nav-item has-treeview menu-open\">";
          echo"<a href=\"entrada_material.php\" class=\"<?php if(basename($_SERVER['SCRIPT_NAME']) == 'entrada_material.php'){echo 'nav-link active'; }else { echo 'nav-link'; };?>\">";
          echo"<i class=\"nav-icon fas fa-sign-in-alt\"></i>";
          echo"<p>Entrada de Material</p>";
          echo"</a>";

          echo"</li>";
              }else{
                echo "nivel não é 2";
              };
        ?>

Sempre acusa erro no segundo echo

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\usina\menu.php on line 33

Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Só não vi a necessidade de tantos echo

<?php
if($_SESSION['usr_id'] == 2){ ?>

	<li class="nav-item has-treeview menu-open">
		<a href="entrada_material.php" 
			class="<?php echo basename($_SERVER['SCRIPT_NAME']) == 'entrada_material.php' ? 'nav-link active' : 'nav-link active'; ?>">

			<i class="nav-icon fas fa-sign-in-alt"></i>
			<p>Entrada de Material</p>
		</a>
	</li>
<?php
}else{
	echo "nivel não é 2";
};
?>
 

Eu também mudei o echo para menu ativo usando o operador ternário

Edited by Alyson Ronnan Martins
Correção leve no código
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Cloud Computing


  • Forum Statistics

    • Total Topics
      148906
    • Total Posts
      644997
×
×
  • Create New...