My database’s not connecting, someone can help me?
<?php
$user="id4132775_tops";
$password="hidden";
$database="";
$hostname="localhost";
$conexao = mysqli_connect($hostname,$user,$password);
@mysqli_select_db($database) or die( "Unable to select database");
$login = $_POST['login'];
$entrar = $_POST['entrar'];
$senha = md5($_POST['senha']);
if (isset($entrar)) {
$verifica = mysqli_query("SELECT * FROM usuarios WHERE login = '$login' AND senha = '$senha'") or die("erro ao selecionar");
if (mysqli_num_rows($verifica)<=0){
echo"<script language='javascript' type='text/javascript'>alert('Login e/ou senha incorretos');window.location.href='login.html';</script>";
die();
}else{
setcookie("login",$login);
header("Location:teste.html");
}
}
?>
Ayu
#2
Hi @easydoom
You have to put your database name in $database=“name”
And + you have to use at the beginning of your code
session_start();
In order to set cookies.
the error continues
<?php
session_start();
$user="id4132775_tops";
$password="hidden";
$database="id4132775_testando";
$hostname="localhost";
$conexao = mysqli_connect($hostname,$user,$password);
@mysqli_select_db($database) or die( "Unable to select database");
$login = $_POST['login'];
$entrar = $_POST['entrar'];
$senha = md5($_POST['senha']);
if (isset($entrar)) {
$verifica = mysqli_query("SELECT * FROM usuarios WHERE login = '$login' AND senha = '$senha'") or die("erro ao selecionar");
if (mysqli_num_rows($verifica)<=0){
echo"<script language='javascript' type='text/javascript'>alert('Login e/ou senha incorretos');window.location.href='login.html';</script>";
die();
}else{
setcookie("login",$login);
header("Location:teste.html");
}
}
?>
Replace this
$conexao = mysqli_connect($hostname,$user,$password);
@mysqli_select_db($database) or die( "Unable to select database");
By this
$conexao = mysqli_connect($hostname,$user,$password,$database);
And while making a query, you should use $conexao
as this
$verifica = mysqli_query($conexao, "SELECT * FROM usuarios WHERE login = '$login' AND senha = '$senha'");
this error appeared
Warning: mysqli_query() expects at least 2 parameters, 1 given in /storage/ssd2/775/4132775/public_html/login.php on line 17
erro ao selecionar
Yep, do the second step, this one
It Works, THANK U VERY MUCH
1 Like
Glad it’s been solved for you.
Always remember, when you grow big, don't forget to upgrade to Hostinger!
Here is a demo of the premium cPanel.
premium.000webhost.ml