Good I am using an AJAX so that the clients register in the web and now I have added a query to him to know if this user already has been registered, step to detail how or I am doing:
AJAX
<script>
$(function(){
$("#formuploadajax1").on("submit", function(e){
e.preventDefault();
var f = $(this);
var formData = new FormData(document.getElementById("formuploadajax1"));
formData.append("dato", "valor");
//formData.append(f.attr("name"), $(this)[0].files[0]);
$.ajax({
url: "incluCuenta/insertar-cliente.php",
type: "post",
dataType: "html",
data: formData,
cache: false,
contentType: false,
processData: false
})
.done(function(res){
if(res=="1"){
toastr["info"]("Registro exitoso!", "Mensaje")
setTimeout(function () {
window.location.href = "login.php"; //will redirect to your blog page (an ex: blog.html)
}, 1500); //will call the function after 2 secs
}else{
$("#mensaje").html(res);
toastr["info"]("Utiliza otro usuario!", "Mensaje")
}
});
});
});
</script>
Here the insertar-cliente
<?php include "../conexion/conexion.php" ?>
<?php
mysqli_set_charset("utf8");
$results = 'SELECT * FROM Usuarios';
$rec = mysqli_query($mysqli, $results);
$verificar_usuario = 0;
while($results = mysqli_fetch_object($rec))
{
if($results->Username == $_POST['email'])
{
$verificar_usuario = 1;
}
}
if($verificar_usuario == 0)
{
$name = $_POST['name'];
$email = $_POST['email'];
$telefono = $_POST['telefono'];
$movil = $_POST['movil'];
$nif = $_POST['nif'];
$direccion = $_POST['direccion'];
$postal = $_POST['postal'];
$poblacion = $_POST['poblacion'];
$provincia = $_POST['provincia'];
$pass = $_POST['pass'];
$sexo = $_POST['sexo'];
$fecha=date('y,m,d');
$results = "INSERT INTO Usuarios (Fecha, Sexo, Nombre, Password, Username, Direccion, Postal, Poblacion, Provincia, Telefono, Movil, Dni, intestado)
VALUES ('$fecha', '$sexo', '$name', '$pass', '$email', '$direccion', '$postal', '$poblacion', '$provincia', '$telefono', '$movil', '$nif', '1')";
if ( !mysqli_query($mysqli, $results)) {
die( 'Error: ' . mysqli_error() );
}
}
else
{
echo '<span class="error">Este usuario ya ha sido registrado anteriormente.</span>';
}
?>
What fails me is that the ajax notifies me, but I need you to notify me if this is repeated the User makes a response and if it is correct is the other answer, something I have done but it does not work well. If it is busy the user leaves the poster of this user and it is already inserted in the bd, but if everything is correct, it shows only the opposite toast and if it is inserted in the bd.