Error Warning: mysqli_fetch_array () and no error returned in mysqli_error

2

I have a simple error and can not find a solution, it seems to me that my problem is different from this answer here .

The error message is this: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, array given in **** on line 22

File connection .php

<?php

$con = mysqli_connect("localhost","root","","sis");

if (mysqli_connect_errno())
  {
  echo "Erro de conexão: " . mysqli_connect_error();
  }

?>

Main file where the error occurs:

include_once('conexao.php');

$senha = '123456';

$sql = "SELECT * FROM arquivo WHERE senha = '$senha'";

$query = mysqli_query($con, $sql) or die(mysqli_error($con));


if(mysqli_affected_rows($con) == 1){

    $resultado = mysqli_fetch_assoc($query);

    $dados = mysqli_fetch_array($resultado);

    echo $dados['idarquivo'];
}

In my database with name sis in table arquivo I have a row where column senha has value 123456 .

Line 22 corresponds to $dados = mysqli_fetch_array($resultado);

    
asked by anonymous 02.03.2017 / 16:38

1 answer

2

There are two statements mysqli_fetch_*() the second receives an array when it should not exist or should receive a resource.

if(mysqli_affected_rows($con) == 1){
    $resultado = mysqli_fetch_assoc($query);
    $dados = mysqli_fetch_array($resultado); //instrução errada

To resolve, just remove it and change the name of the variable in echo from $dados to $resultado .

    
02.03.2017 / 16:51