If loop registration error

Asked

Viewed 46 times

0

I have a registration form:

    <form action="Cadastro.php" method="post"> 
         Nome de Usuário: <br> 
         <input class="form-control" type="text" placeholder=" algo parecido com o seu nome" size="30px" name="nomeUser"><br>
         Email:<br>
         <input class="form-control" type="text" placeholder=" [email protected]" size="30px" name="email"><br>
         Senha: <br>    
         <input class="form-control" id="senha" type="password" placeholder=" min. 8 caracteres" size="30px" name="senha"><br>
         Confirmação de Senha: <br>
         <input class="form-control" id="senhaconfirm" type="password" placeholder=" confirme sua senha" size="30px" onblur="comparar()">
         <br><input class="btn btn-embossed btn-info" type="submit" value="Cadastrar">
         <input class="btn btn-embossed btn-primary" type="reset" value="Esquecer">
</form>

and my.php register has two queries to the bank, a SELECT(query if there is another person with the same username) and another INSERT (that cadastra), this Insert is inside an if along with the creation of a folder, the folder is created correctly, but the user is not registered in the bank:

    <?php
    $nomeUser = $_POST["nomeUser"];
    $email = $_POST["email"];
    $senha = $_POST["senha"];

    //Conectando ao banco de dados
    $mysqli = new mysqli("localhost", "root", "", "authenticationteste");
    if ($mysqli->connect_errno) {
        echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
    }


    //Consultando banco de dados
    $authentic = $mysqli->query("SELECT * FROM login WHERE nomeUser='".$nomeUser."'");
    $numrow = mysqli_num_rows($authentic);
    if($numrow > 0){
        echo "<script>
            var confirma = confirm('Erro: O nome de usuário que você requisitou já exite. Tente outro!');
            if(confirma){location.href='index.php#cadastro';}else{location.href='index.php';}
            </script>";
    }else{
        echo "$nomeUser";
        $res = $mysqli->query("insert into login(nomeUser,email,senha,nomeFolder)values('". $nomeUser . "','".$email."','".$senha."');");
        //mkdir ("C:/Users/e/Documents/Uploads/$nomeUser", 0700 );
    }

?>

Previously without the SELECT code that looked for other entries, it was working properly. I don’t know if the problem is having two queries or if it is in the if loop, but I know that the post is working properly and the connection too. If anyone can help me I’d appreciate it.

1 answer

3


Apparently the column value is missing nomeFolder on your internet.

It should be like this:

$res = $mysqli->query("insert into login(nomeUser, email, senha, nomeFolder) values('". $nomeUser . "', '".$email."', '".$senha."', 'C:/Users/e/Documents/Uploads/".$nomeUser."');");

I also recommend that preferably for the use of PDO, as it is receiving data directly from the form is also recommended the use of Prepared statement for greater security.

  • Damn, man, that’s right, thanks. I tried to use the PDO, but I couldn’t implement it in the login part and I just let it go. But thanks for your help

  • No problem dude, still recommend you study PDO, so get the hang of it you don’t want to use the other options. Anyway use the Prepared statetment of mysqli, he also has this option.

Browser other questions tagged

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