0
I am not being able to do user authentication, just redirecting to the part where "it is not possible to register user".
<?php
$login = $_POST['login'];
$senha = MD5($_POST['senha']);
$connect = mysqli_connect('nome_do_servidor','nome_de_usuario','senha');
$db = mysqli_select_db('nome_do_banco_de_dados');
$query_select = "SELECT login FROM usuarios WHERE login = '$login'";
$select = mysqli_query($query_select,$connect);
$array = mysqli_fetch_array($select);
$logarray = $array['login'];
if($login == "" || $login == null){
echo"<script language='javascript' type='text/javascript'>alert('O campo login deve ser preenchido');window.location.href='cadastro.html';</script>";
}else{
if($logarray == $login){
echo"<script language='javascript' type='text/javascript'>alert('Esse login já existe');window.location.href='cadastro.html';</script>";
die();
}else{
$query = "INSERT INTO usuarios (login,senha) VALUES ('$login','$senha')";
$insert = mysqli_query($query,$connect);
if($insert){
echo"<script language='javascript' type='text/javascript'>alert('Usuário cadastrado com sucesso!');window.location.href='login.html'</script>";
}else{
echo"<script language='javascript' type='text/javascript'>alert('Não foi possível cadastrar esse usuário');window.location.href='cadastro.html'</script>";
}
}
}
?>
At last
else
, placeecho mysqli_error($connect)
to display the latest error message in Mysqli.– Woss
curiosity, can reverse the order within parentheses
$select = mysqli_query($query_select,$connect);
would not be$select = mysqli_query($connect,$query_select);
– user60252
Welcome to this post https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079
– user60252