Error in login system using SQL Server. Resource(7) of type (SQL Server Statement)

Asked

Viewed 63 times

0

I am trying to make a login system between PHP and SQL Server and is giving the error Resource(7) of type (SQL Server Statement).

index php.

<form class="form-horizontal" id="FormLogin" action="login.php" method="post">
   <div class="form-group">
      <label for="login">Login</label>
      <input type="text" class="form-control" id="login" name="login" placeholder="Entre com o seu Login">
   </div>
   <div class="form-group">
      <label for="senha">Senha</label>
      <input type="password" class="form-control" id="senha" name="senha" placeholder="Entre com a sua Senha">
   </div>
   <button type="reset" class="btn btn-default">Limpar</button>
   <button type="submit" class="btn btn-danger pull-right">Entrar</button>
</form>

login.php

<?php

include 'conexao.php';
include 'banco-usuario.php';

$usuario = buscaUsuario($conn, filter_input(INPUT_POST, 'login'), filter_input(INPUT_POST, 'senha'));
var_dump($usuario);

php database.

$query = "select * from usuario where login = '{$login}' and senha = '{$senha}'";

//$resultado = mysqli_query($conn, $query); //MySQLi
$resultado = sqlsrv_query($conn, $query); //SQL Server


return $resultado;

}

I don’t know what to do about it. I want to make a system that uses login.

  • 1

    I’m not missing the sqlsrv_fetch() ai? as in question

  • Could be. How would that look? Return sqlsrv_fetch($result);

  • Yes, it might be a return sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC), this will return only one line. If you want to use Prepared statements with sql server see this other reply

  • Put in a way that I can mark as an answer

  • Gave error of its form but Return sqlsrv_fetch($result) works.

1 answer

0

The message resource(7) of type (SQL Server Statement) is not an error, is a representation in text form of Resource (which can be a query). Your query has been processed with sqlsrv_query() but failed to extract the result with sqlsrv_fetch_array().

To fix add a Return with the result already extracted:

$resultado = sqlsrv_query($conn, $query);
return sqlsrv_fetch_array($resultado, SQLSRV_FETCH_ASSOC);

Browser other questions tagged

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