User registration system

Asked

Viewed 148 times

0

I already have the system, only I don’t know how to develop the mistakes. For example: Passwords do not match, user already exists, email already exists.

    <?php

include('../includes/config.php');

$usuario    = $_POST ["usuario"];   
$email  = $_POST ["email"];
$senha = MD5($_POST["senha"]);
$query = "INSERT INTO `users` ( `usuario` , `email`, `senha`, `usuario_id` ) 
VALUES ('$usuario', '$email', '$senha', '')";

mysql_query($query);

echo "";

?> 

And a form:

    <form action="registrar.php" method="post">
    <input name="usuario" type="text" id="usuario"><br>
    <input name="email" type="text" id="email"><br>
    <input name="senha" type="password" id="senha">
    <input name="senha2" type="password" id="senha2">
    </form>

The system already works, already registered and everything, only the errors are missing. And I wanted to appear a browser script with the written error.

1 answer

0

Well that and simpler than it looks, just pass the bugs to the $_SESSION, and present them in the registration area. you have to start your code with session_start();

<?php
session_start();
// balbalbal mais codigo qualquer aqui

?>
<?php
   if(isset($_SESSION['erros']))
    {
   foreach($_SESSION['erros'] as $erro)
    {
        echo "<h2>$erro</h2>";
    }
    }
?>
<form action="registrar.php" method="post">
    <input name="usuario" type="text" id="usuario"><br>
    <input name="email" type="text" id="email"><br>
    <input name="senha" type="password" id="senha">
    <input name="senha2" type="password" id="senha2">
    </form>

In the area of trying to register

<?php
session_start();
$_SESSION['erros'] = "";
$erros = array();
$i = 0;
// Quando o utilizador tiver algum erro basta adicionar isto
$i++;
$erros[$i] = "Erro nao sei qual.";

// No fim da detencao dos erros basta meter isto
$_SESSION['erros'] = $erros;
header("Location: register.php"); // Nao sei se o ficheiro para registar e esse mas vou tentar adivinhar xD

Browser other questions tagged

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