Doubt in PHP database connection

Asked

Viewed 126 times

3

I have a question in a code in PHP.

My code is generating several alerts:

Print dos erros

And it seems to me that the same is not making connection with the database, because I am sending him to print some data and it does not print anything on the screen.

I’m going to put some code here:

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

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

$result = mysqli_query("SELECT * FROM usuario WHERE usuario='$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");
}

?>
  • 1

    Man, every Warning has a message. Just read the messages and see what each one says.

  • Pass the connection as the fourth argument of mysqli_connect() then don’t forget to pass the connection as the first argument in mysqli_query()

  • Would that be:<? php $connect = mysqli_connect("localhost","root","","painel_admin") or die ("Connection error"); mysqli_select_db("painel_admin"); ?>

  • Passes the name of the bank directly on mysqli_connect : $conectar = mysqli_connect("localhost","root", "", "painel_admin");

  • 1

    It was right to go straight to mysaqli_connect, THANK YOU!!

No answers

Browser other questions tagged

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