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

Asked

Viewed 615 times

2

I have a simple mistake and I 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 connected.php

<?php

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

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

?>

Main file where error happens:

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 name database sis on the table arquivo i have a row in which column senha has the value 123456.

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

  • Has two mysqli_fetch_*() just one or the other, the second should not exist. It is receiving an array ($resultado) when maybe you should receive a Resource ($query). Then just change to echo $resultado['idarquivo'];

  • @rray thanks for the reply, if possible put your answer so that I put my question as answered.

1 answer

2


There are two instructions 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 simply remove it and rename the variable in echo $dados for $resultado.

Browser other questions tagged

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