Jump to content
Sign in to follow this  
noobre

Erro no Fetch Array

Recommended Posts

noobre

Boas ando a trabalhar neste projecto e ultimamente está me a dar um erro que tecnicamente não estou a ver onde é a causa do mesmo.

Esta é a primeira página: [

<?php
    include "config.php";

    if(!isset($_SESSION["autenticado"])
    or  $_SESSION["autenticado"]!=true){
        header("Location: index.php?erro=1");
        exit();
    }
    $sql="select * from empresa WHERE id_empresa=".$_GET["id_empresa"];
    
    $linhas=mysqli_query($ligacao,$sql);
    $linha=mysqli_fetch_array($linhas);
?>
<!DOCTYPE html>
<html>
<title>Gestao de Empresas</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="css/main.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<body>
<ul>
<li class="dropdown">
  <a href="javascript:void(0)" class="dropbtn">Perfil</a>
  <div class="dropdown-content">
    <a href="logout.php">Logout</a>
  </div>
</li>
<li><a href="empresas.php">Inicio</a></li>
</ul>

    <center>
    <div style="padding-left:16px; padding-top: 50px">
        <h2>Departamentos</h2>
        <p>Empresa: <?php echo $linha["nome"]; ?></p>
    </div>
    
    <table id="empresas" style="padding-top: 43px;">
    
        <tr>
            <th>Nome</th>
            <th>Nome</th>
            <th>Descrição</th>
            <th rowspan="1" colspan="2">Operações</th>
        </tr>
        <?php
        while($linha=mysqli_fetch_array($linhas)) {
        ?>
        <tr>
            <td><?php echo $linha["nome"]; ?> </td>
            <td><?php echo $linha["descricao"]; ?> </td>

            <td style="text-align: center">
                <?php echo "<a href='main.php?id_empresa=" . $linha["id_empresa"] . "'" ?>
                ><i class="fa fa-search-plus" style="color: white" aria-hidden="true"></i></td>
                
            <td style="text-align: center">
                <?php echo "<a href='empresa_editar.php?id_empresa=" . $linha["id_empresa"] . "'" ?>
                ><i class="fa fa-pencil-square-o" style="color: white" aria-hidden="true"></i></td>

            <td style="text-align: center">
                <?php echo "<a href='empresa_eliminar.php?id_empresa=" . $linha["id_empresa"] . "'" ?>
                ><i class="fa fa-times" style="color: white" aria-hidden="true"></i></td>
                
        </tr>
        <?php } ?>
            <td style="text-align: center">
                <?php echo "<a href='departamento_adicionar.php?id_empresa=" . $linha["id_empresa"] . "'" ?>
                ><i class="fa fa-plus" style="color: white" aria-hidden="true"></i></i></td>      
    </table> 
        
    </center>
    
<script>
    function myFunction() {
    var x = document.getElementById("myNavbar");
    if (x.className === "navbar") {
        x.className += " responsive";
    } else {
        x.className = "navbar";
    }
}
</script>
</body>
</html>

 

Nesta segunda página dá-me erro na linha: 

$linha=mysqli_fetch_array($linhas);
<?php
    include "config.php";
    
    $sql="select * from empresa WHERE id_empresa=".$_GET["id_empresa"];
    
    $linhas=mysqli_query($ligacao,$sql);
    $linha=mysqli_fetch_array($linhas);
?>    
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" type="text/css" href="css/main.css">
    <link rel="stylesheet" type="text/css" href="css/theme.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <title>Gestao de Empresas</title>
</head>
<body>
<h1 >Adicionar departamento</h1>
            <form action="departamento_adicionar_gravar.php" method="POST" enctype="multipart/form-data">
                <p>
                    <label for="nome">Nome:</label><br>
                    <input type="text" name="nome" placeholder="Nome">
                </p>
                <p>
                    <label for="descricao">Descricao:</label><br>
                    <input type="text" name="descricao" placeholder="Descricao">
                </p>
                <!-- <p>
                    <label for="foto">Foto:</label><br>
                    <input type="file" name="foto" />
                </p>-->
                <p>
                    <input type="submit" name="submit" value="Adicionar">
                </p>
            </form>
    <center>
        <?php echo  "<a style='color: white' href='departamentos.php?id_empresa=" . $linha["id_empresa"] . "' " ?>
        >Voltar atrás
    </center>
</body>
</html>

 

Share this post


Link to post
Share on other sites
N3lson

Estás-te a repetir


$linha=mysqli_fetch_array($linhas);

e depois em 

while($linha=mysqli_fetch_array($linhas)) 


You can't do it, kid. But don't worry, my boy. You're not the only one. No one else can do it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.