Run include inside if

Asked

Viewed 276 times

0

Hello

I need to add one include within a function if but at run time does not read the added include. Someone can give me a hint where is the error.

Menu content.html

<div id='menutopo'>
  <div id= 'menu1'>
    <button id='dropbtn1'>Cadastro</button>
        <div id='dropdown-content1'>
            <a href='cadastrocliente.html'>Clientes</a>
            <a href='cadastroprodutos.php'>Produtos</a>
        </div>
  </div>
  <div id='menu2'>  
    <button id='dropbtn2'>Moveis</button>
        <div id='dropdown-content2'>
            <a href='fichademoveis.html'>Criar Ficha</a>
            <a href='#'>Consulta de Ficha</a>
        </div>
</div>
   <div id= 'menu3'>
     <button id='dropbtn3'>Consulta</button>
        <div id='dropdown-content3'>
            <a href='consultadecliente.php'>Clientes</a>
        </div>
  </div>
</div>

php file that checks and confirms the variareis will run an html.

<?php
  include "in/conecta.inc";

?>

<?php


if($cont==1 && $cont2=1){
    echo "<!DOCTYPE html>

  <html lang='pt-br'>
  <head>
   <meta charset='UTF-8'/>
  <meta name='description' content='Bem vindo ao Bsis vendas'>
  <meta name='viewport' content='width=device-width, user-scalable=no,      initial-scale=1.0,maximum-scale=1, minimun-scale=1'>
   <link rel='icon' type='image/png' href='imagens/favicon.png'>
    <link rel='stylesheet' type='text/css' href='css/estilo.css'>
   <link rel='stylesheet' type='text/css' href='css/login.css'>



  </head>
  <body>
  <header>


  <?php

     include ('in/menu.inc');?>

   </header>
  <div id='bordacabecalho'></div>

  <footer>
   <nav id='menurodape'>
      <ul>
          <li><a href='manual.html'>Manual</a></li>
      </ul>
      </nav>


    </footer>
    </body>
     </html>";
            }
     else{

      echo "<!DOCTYPE html>

     <html lang='pt-br'>
     <head>
      <meta charset='UTF-8'/>
     <meta name='description' content='Bem vindo ao Bsis vendas'>
     <meta name='viewport' content='width=device-width, user-scalable=no, init ial-scale=1.0,maximum-scale=1, minimun-scale=1'>
     <link rel='icon' type='image/png' href='imagens/favicon.png'>
      <link rel='stylesheet' type='text/css' href='css/estilo.css'>
     <link rel='stylesheet' type='text/css' href='css/login.css'>


     <script src='javascript/login.js'>

     </script>
     </head>
     <body>
     <header>
      <a href='index.html'><img id= 'logo' src='imagens/baixinhologo.png'></a>
    </header>
    <div id='bordacabecalho'></div>

     <form id='login' action= 'login.php' method='post'>
   <p>Login:<input type='text' name='login' placeholder= 'login'/></p>
   <p>Senha:<input type='password' name='senha' placeholder='senha'/></p>

   Senha incorreta tente novamente

   <input type='submit'id='botao' name='botaoo' value='Entrar'/>

  </form>
  <footer>
  <nav id='menurodape'>
    <ul>
        <li><a href='manual.html'>Manual</a></li>
    </ul>
</nav>


 </footer>
  </body>
 </html>";}
 ?>

2 answers

2


Editing:

<?php
include "in/conecta.inc";

$doc = $_POST['login'];
$senha = $_POST['senha'];
$try = mysqli_query($conn, "select login from usuarios where login='$doc' and senha='$senha'");
$cont = mysqli_num_rows($try);
$tru = mysqli_query($conn, "select senha from usuarios where senha='$senha' and login='$doc'");
$cont2 = mysqli_num_rows($tru);

if ($cont == 1 && $cont2 = 1) {
    ?>
    <!DOCTYPE html>

    <html lang='pt-br'>
        <head>
            <meta charset='UTF-8'/>
            <meta name='description' content='Bem vindo ao Bsis vendas'>
            <meta name='viewport' content='width=device-width, user-scalable=no, initial-scale=1.0,maximum-scale=1, minimun-scale=1'>
            <link rel='icon' type='image/png' href='imagens/favicon.png'>
            <link rel='stylesheet' type='text/css' href='css/estilo.css'>
            <link rel='stylesheet' type='text/css' href='css/login.css'>



        </head>
        <body>
            <header>


                <?php
                include 'in/menu.inc';
                ?>

            </header>
            <div id='bordacabecalho'></div>

            <footer>
                <nav id='menurodape'>
                    <ul>
                        <li><a href='manual.html'>Manual</a></li>
                    </ul>
                </nav>


            </footer>
        </body>
    </html>
    <?php
} else {
    ?>
    <!DOCTYPE html>

    <html lang='pt-br'>
        <head>
            <meta charset='UTF-8'/>
            <meta name='description' content='Bem vindo ao Bsis vendas'>
            <meta name='viewport' content='width=device-width, user-scalable=no, init ial-scale=1.0,maximum-scale=1, minimun-scale=1'>
            <link rel='icon' type='image/png' href='imagens/favicon.png'>
            <link rel='stylesheet' type='text/css' href='css/estilo.css'>
            <link rel='stylesheet' type='text/css' href='css/login.css'>


            <script src='javascript/login.js'>

            </script>
        </head>
        <body>
            <header>
                <a href='index.html'><img id= 'logo' src='imagens/baixinhologo.png'></a>
            </header>
            <div id='bordacabecalho'></div>

            <form id='login' action= 'login.php' method='post'>
                <p>Login:<input type='text' name='login' placeholder= 'login'/></p>
                <p>Senha:<input type='password' name='senha' placeholder='senha'/></p>

                Senha incorreta tente novamente

                <input type='submit'id='botao' name='botaoo' value='Entrar'/>

            </form>
            <footer>
                <nav id='menurodape'>
                    <ul>
                        <li><a href='manual.html'>Manual</a></li>
                    </ul>
                </nav>


            </footer>
        </body>
    </html>
    <?php
}

You just didn’t close the if nor closed the echo appropriately:

<?php
if($cont==1 && $cont2=1){
    echo "<!DOCTYPE html>

    <html lang='pt-br'>
    <head>
    </head>
    <body>
   <header>

    <?php

    include('in/menu.html');

     ?>";
}

Another way is way:

<?php
if($cont==1 && $cont2=1){
?>
    <!DOCTYPE html>

    <html lang='pt-br'>
    <head>
    </head>
    <body>
   <header>

    <?php

    include('in/menu.html');
}

  • Hi the items you mentioned were made, but they didn’t appear in these lines, unfortunately my problem continues and I don’t know what I’m doing wrong yet

  • You can post the entire code?

  • edited the full code

  • Try this last code. By the way, what extension is this .inc?

  • Serious young man does not know the extent .inc. This extension more suitable for use of include. Your second code does not make sense because it opens <?php and doesn’t close with ? >. Thanks for the help.

  • You are completely wrong. Use all extensions with .php. I know that .inc is a convention, but not all servers are configured to pass this extension as PHP codes. Another thing, In PHP files it is not necessary to close the tags. Feel free to read the best practice conventions in PHP programming: http://www.php-fig.org/. Spoke, young man!

  • Thank you so much for the instructions, I agree that I may be wrong I will study more to try to understand better. Greetings for the concern in teaching.

Show 2 more comments

0

After some reading I found the reason for my mistake, where help from Eduardo Almeida was extremely useful giving the paths to understand the code. Read the instructions given by him

Browser other questions tagged

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