Error connecting to database

-1

I try to connect to my bd, but it gives the error "Failed to connect!"

The data that is in my bd is:

Database: test Table: Customers

I'm trying to connect through PHP

    <?php


$conn = @mysqli_connect("localhost", "root", "", "teste") or die("Falha ao conectar!");

?>

and the validation:

<?php


require_once "conexao.php";

$email = $_GET['idemail'];
$cpf = $_GET['cpf'];
$query = "SELECT * FROM clientes WHERE cpf = '$cpf' AND email = '$email'";
$querySelect = mysqli_query($conn,$query);

if(mysqli_num_rows($querySelect) <=0){
    echo"<script type='text/javascript'>alert('Email ou cpf incorretos');window.location.href='index.html';</script>";
    die();
}else{
    setcookie("login", $cpf);
    header("Location:Postagem.html");
}

But whenever I put the correct or incorrect data that is in my bd, it gives the same error as "Failed to connect!"

    
asked by anonymous 10.11.2017 / 16:48

1 answer

1

If this change brings an error message, I'll edit the answer to help you fix:

// cria conexao
$conn = new mysqli("localhost", "root", "", "teste");
// exibe motivo da falha, caso haja alguma
if ($conn->connect_error) {
    die("Falha ao conectar!, Motivo: " . $conn->connect_error);
} 
    
10.11.2017 / 17:13