1
I have this code below:
<?php
$conecta_no_banco = require_once ('conecta_db.php');
$login = $_POST['login'];
$senha = $_POST['senha'];
$sql = mysqli_query($conecta_no_banco,"SELECT usuario FROM gerenciador_de_socios.autenticacao_usuarios") or die("Erro!");
$row = mysqli_num_rows($sql);
if(!$login || !$senha) {
echo "Você deve digitar sua senha e login!";
exit;
}
if ($row > 0) {
echo "OK!";
}
mysqli_close($conecta_no_banco);
?>
When I run, it gives the error:
Warning: mysqli_query() expects Parameter 1 to be mysqli, integer Given
What I’m doing wrong?
This is one of the most frequently asked questions about PHP and the error itself tells the reason.... https://answall.com/questions/28184/mysql-fetch-array-expects-parameter-1-to-be-resource-boolean-given-in, https://answall.com/search?tab=votes&q=expects%20parameter%20given%20%5bphp%5d, the problem is still on the line depending on the
$conecta_no_banco
, that this omitted in the code, he is the problematic.– Inkeliz
@Inkeliz in this case would have to see what it has in conecta_db.php. In conecta_db.php, for your code to work, it must have something at the end like
return $variavel_de_conexao
– MarceloBoni
Now that I’ve noticed that, maybe that’s the problem, but there’s no way to know.
– Inkeliz
I have never done anything like this, when I give a require_once, I usually use the functions and variables created in the "child" file (which comes from require_once) in the "parent" file, if Return is omitted the value that returns is an integer (1) if the file exists.
– MarceloBoni