Error with PHP function

Asked

Viewed 53 times

0

Hello, I am developing this system for study purposes and whenever I try to do some operation like register, edit or delete I get the error message: "Fatal error: Call to Undefined Function usuario_logado() in /opt/lampp/htdocs/projects/estudandophp/menu_administrador.php on line 28" but the operation is completed. What I have researched is as if the class where the function is defined does not exist but I think that is not the case. What am I doing wrong? Below the screens to give a sense of what I’m doing:

Follow the application source code: Github

  • 1

    In the file menu_admin.php Voce this calling usuario_logado() but at no point in the file did you declare that function. To solve the problem, create the function in that file or use a require Iu include to include the file that has the user function

  • 1

    You must import the file seguranca.php using the method require_once() before using this function. Whenever you create a class or function in a separate file you should import it to the page you intend to use

  • Thanks for the feedback. So, I had not made the import because I am including the file 'menu_administrador.php' in 'menu.php' and there is what I am doing 'require' of 'segurnca.php'. Having said that I realized that the problem was that when I did some operation in the bank I was calling directly the page 'lista_alunos.php' and calling this way none of the imports were being made.

2 answers

0

Behold:

<?php include_once 'segurança.php';?>
<nav id="barra_navegacao"class="navbar navbar-inverse navbar navbar-fixed-top">
            <div class="container-fluid">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="menu.php"><font style="color: #337ab7"><b>Sistema X</b></font></a>
                </div>
                <div id="navbar" class="navbar-collapse collapse">
                    
                    <ul class="nav navbar-nav">
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><small>GERENCIAMENTO</small><span class="caret"></span></a>
                            <ul class="dropdown-menu">
<!--                            <li class="dropdown-header">Teste</li>
                                <li role="separator" class="divider"></li>-->

                                <li><a href="menu.php?link=2"><small><span class="glyphicon glyphicon-education"></span> ALUNO</small></a></li>

                            </ul>
                        </li>
                    </ul>                    
                    <ul class="nav navbar-nav navbar-right">
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php usuario_logado();?><span class="caret"></span></a>
                            <ul class="dropdown-menu">
                                <li><a href="sair.php"><span class="glyphicon glyphicon-log-out"></span> <small>SAIR</small></a></li>
                            </ul>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>

  • Thanks for the feedback. So, I had not made the import because I am including the file 'menu_administrador.php' in 'menu.php' and there is what I am doing 'require' of 'segurnca.php'. Having said that I realized that the problem was that when I did some operation in the bank I was calling directly the page 'lista_alunos.php' and calling this way none of the imports were being made.

0


Just add the file php security. at the beginning of the file menu_admin.php for example:

<?php require_once 'seguranca.php'; ?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.