Connection error with database [duplicate]

0

Good morning! I have a panel in php and it is not connecting to the DB. Any password that I enter, the password or the wrong user.

Here is the snippet of the code 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 is the snippet 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");
?>

Thank you in advance!

    
asked by anonymous 12.07.2017 / 14:39

1 answer

0

Here's 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");
}
    
12.07.2017 / 14:46