Error in database connection

Asked

Viewed 84 times

0

Good morning! I have a panel in php and the same is not connecting to DB. Any password I enter, password or incorrect user.Como na imagem

Follow the code snippet that makes the connection:

<?php
session_start();
$usuariot = $_POST['usuario'];
$senhat = $_POST['senha']; 
include "conexao.php";

$result = mysqli_query("SELECT * FROM usuario WHERE login='$usuariot' AND senha='$senhat' LIMIT 1");
$resultado = mysqli_fetch_assoc($result);
if(empty($resultado)){
    $_SESSION['loginErro'] = "Usuário ou senha inválido";
    header ("Location: login.php");
}

?>

And below the excerpt of the code that connects to the database:

<?php
$conectar = mysqli_connect("localhost","root","") or die ("Erro na conexão");
mysqli_select_db($conectar, "painel_admin");
?>

Thanks in advance!

  • Remember I mentioned yesterday in the other question? no mysqli_query() you need to pass the connection as first argument always.

  • You mean like: $result = mysqli_query("localhost","SELECT * FROM user WHERE login='$usuariot' AND password='$senhat' LIMIT 1");

  • Thus: mysqli_query($conectar, "SELECT * FROM usu....").

  • Thanks rray! It worked

1 answer

0

Follow an example

Connection

$mysqli = new mysqli($servidor, $usuario, $senha, $banco);

if (mysqli_connect_errno()) trigger_error(mysqli_connect_error());

YOUR SELECT

$sql = "SELECT * FROM usuario WHERE login='$usuariot' AND senha='$senhat' LIMIT 1";
$query = $mysqli->query($sql);

$resultado = mysqli_fetch_assoc($query);
if(empty($resultado)){
    $_SESSION['loginErro'] = "Usuário ou senha inválido";
    header ("Location: login.php");
}
  • Now it’s worked out! Thank you all very much!

  • @Pedroribeiro If the answer has helped you, you could dial as solved and give +1

  • I’ve already put Rafael, but I’m new mebro, so does not appear.

Browser other questions tagged

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