0
It follows below my code. It does everything, but hangs on the "user already registered" message even if I insert a different user into the field!
Remarks:
$con
is the connection to the database that is correct;
login is the id in the page field where you enter the data;
mysqli use;
the table is "users"
$login = $_POST['login'];
$senha = $_POST['senha'];
#Recolhendo os dados do formulário
$loginrecolha = mysqli_real_escape_string($con, $login);
$senharecolha = mysqli_real_escape_string($con, $senha);
# Verificando apenas um campo, no caso login.
$sql = $con->query("SELECT login FROM usuarios WHERE login='$loginrecolha'");
if(mysqli_num_rows($sql) > 0){
echo "Este usuário já existe";
exit();
} else {
if(!$con->query("INSERT INTO usuarios (login,senha) VALUES
('$login','$senha')")) die ('Os dados não foram inseridos');
echo "Dados inseridos com sucesso";
}
How so hangs on the message "user already exists"? It means it always falls in the IF?
– Neto Costa
this friend... if I register any user existing in the table or does not fall in the if
– Cleiton Back
If you take the instruction you’re in
$sql
and run in the bank, it finds some record ?– 8biT
yes finds 1 record which is what you have
– Cleiton Back