Error connecting to database

Asked

Viewed 72 times

-1

I try to make the connection in my comic, but keeps giving the error "Failed to connect!"

The data in my comic book is:

Data Base: a test Table: customers

trying to connect by PHP

    <?php


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

?>

and 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 comic, gives the same error "Failure to connect!"

  • check if you really have a database with a test, root user and empty password. or change your error message to write which error you made, not just which failed

  • I changed the error message and when I go to test, it gives the same previous message

  • 1

    the problem is in the connection file, remove@, it is suppressing the errors. switch to or die("Failed to connect!". mysqli_connect_error());

  • keeps making the same mistake

  • but what about the additional information? nothing? no more messages? if you have removed @ and put mysqli_connect_error() in the log, and yet have not changed anything, I must ask, you have saved the file?

  • Right to change to : $Conn = ("localhost", "root", ""test") or die("Failed to connect!".mysqli_connect_error()); , and I saved nothing, and I saved it

Show 1 more comment

1 answer

1


if this change brings an error message, I edit the response to help you fix it:

// 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);
} 

Browser other questions tagged

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