I'm doing a site that has a login field, which logs into the admin sector and can insert, delete, and change database items. The registration page is not entering the database. In fact, it is performing no function that it should perform. Should not allow registration if the passwords do not hit, should not allow in case any field was missing, and if everything was right, you should simply register and take the login screen.
Could you help me? Here are the codes:
<body>
<div class="container container-twelve">
<div class="four columns offset-by-four">
<h1 class="titles">Cadastro</h1>
<?php if(isset($_SESSION["success"])) {?>
<p><?= $_SESSION["success"] ?></p>
<?php }?>
<?php unset($_SESSION["success"]); ?>
</div>
<div class="four columns offset-by-four" id ="login">
<form action="cadastra_usuario.php" method="post">
<label for="nome">Nome</label>
<input type="text" name="nome" placeholder="Digite seu nome">
<label for="email">Email de usuário </label>
<input type="text" name="email" placeholder="Seu email para login">
<label for="senha">Senha</label>
<input type="password" name="senha" placeholder="Sua senha">
<label for="senha2">Repita sua senha</label>
<input type="password" name="senha2" placeholder="Repita sua senha">
<input type="submit" value="Cadastrar">
</form>
<p><a href="index.php"> << Voltar para o site</a></p>
<p><a href="login.php"> Já tenho um cadastro >> </a></p>
</div>
</div>
</body>
cadastra_usuario.php:
<?php
include('conecta.php');
include('functions.php');
include('function_usuario.php');
$senha = $_POST['senha'];
$senha2 = $_POST['senha2'];
$cadastra = cadastraUsuario($_POST['nome'], $_POST['email'], $_POST['senha']);
if($senha != $senha2){
$_SESSION["danger"] = "As senhas não conferem!";
header("Location: cadastro.php");
}
if($cadastra == null){
$_SESSION["danger"] = "Complete todos os campos!";
header("Location: cadastro.php");
} else {
$_SESSION["success"] = "Usuário cadastrado com sucesso.";
header("Location: login.php");
}
?>
And the function:
function cadastraUsuario($conexao, $nome, $email, $senha){
$query = "insert into usuarios (nome, email, senha) values ('{$nome}', '{$email}', '{$senha}')";
return mysqli_query($conexao, $query);
}
If you need the complete codes, please ask me.