Register loop in if loop

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 cadastro.php has two queries to the bank, a SELECT (ask if there is another person with the same username) and another INSERT (which registers), that insert is inside an if together 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 was looking for other records, it was working correctly. I do not know if the problem is in having two queries or if it's in the if loop, but I know the post is working properly and the connection as well. If anyone can help me, I appreciate it.

    
asked by anonymous 17.01.2017 / 19:42

1 answer

3

The value of the FolderName column in your insert is apparently missing.

It should look 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 the PDO, as it is receiving data directly from the form it is also recommended to use a prepared statement for greater security.

    
17.01.2017 / 19:49