-3
When I go to the page to register, it already displays the message "This login already exists" and does not even let me enter the data. I think the error is in PHP, but I don’t know where.
If anyone can help me solve it, I haven’t implemented any security systems either because I’m learning and I don’t know if there are other bugs in the code.
This is the code of the register:
<?php
$login = $_POST['login'];
$senha = MD5($_POST['senha']);
$connect = mysql_connect('nome_do_servidor','nome_de_usuario','senha');
$db = mysql_select_db('nome_do_banco_de_dados');
$query_select = "SELECT login FROM usuarios WHERE login = '$login'";
$select = mysql_query($query_select,$connect);
$array = mysql_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 = mysql_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>";
}
}
}
?>
I believe that information is missing. The code you posted does not show where the return comes from "User already exists."
– David Alves
The function
mysql_query()has already been removed from php just to warn.– rray
The message is "'That login already exists" (tidied up now) in the first echo within the second if,
– Guilherme
Enter the code of
cadastro.html, after all that’s where the problem occurs– Costamilam
Just to reinforce what @rray said, the functions
mysql_are obsolete and have been removed in php 7, usemysqli_orPDO– Costamilam
Welcome Guilherme Geek, don’t miss this image https://i.stack.Imgur.com/evLUR.png and read this post https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079
– user60252