Hello, guys! Currently, to check if a user name is unique, I do the most basic. I send the POST to a PHP page that checks in MySQL, only then returns the error. cadastro.php:
<form role="form" action="https://<?php print $_SERVER['HTTP_HOST']; ?>/cadastro/" enctype="multipart/form-data" method="post">
<div class="form-group">
<label>Usuário</label>
<input name="usuario" type="text" class="form-control" minlength="4" placeholder="Digite um usuário único..." required>
</div>
<button type="submit" class="btn">Criar</button>
</form>
verify.php:
<?php
$SqlCheck = $ConDB -> prepare("SELECT COUNT(*) AS 'ContUser' FROM
'usuarios' WHERE 'userName'=:USER;");
$SqlCheck -> bindParam(":USER", $_POST['usuario']);
$SqlCheck -> execute();
$RowCheck = $SqlCheck -> fetch(PDO::FETCH_OBJ);
$ContUser = $RowCheck -> ContUser;
if ($ContUser == 0) {
/* Realiza o cadastro */
} else {
echo 'Usuário já existe';
}
?>
Is it possible to do this check while typing in the input, eg from the 4 character shown on the bottom line if the user already exists? In real time?
Maybe in jQuery or ajax give to do, but I do not handle any of these languages.