Ver Mensaje Individual
  #14 (permalink)  
Antiguo 19/08/2015, 15:07
mauricio1020
 
Fecha de Ingreso: mayo-2015
Mensajes: 63
Antigüedad: 9 años, 8 meses
Puntos: 1
Respuesta: Validar un registro antes de insertar

mire ya lo probe y le hize solo unos include y me funciono asi copia y pega y me cuentas:

index.php:
Código PHP:
<html
  <
head
  <
title></title
    <
script type="text/javascript" src="css/codigo.css"></script> 
  
  <script> 
  document.addEventListener("DOMContentLoaded", function(){ 
    var form = document.querySelector("#datos"),
    input = document.querySelector("#correo"), 
    span = document.querySelector("#mensaje"),
    ajax, envio;
 
input.addEventListener("blur", function(){
    ajax = new XMLHttpRequest();
    ajax.open("GET", "comprobar.php?correo=" + this.value, true);
    ajax.send();
    ajax.addEventListener("load", function(){
        if (this.status == 200){
            if (this.responseText == "yes"){
                span.innerHTML = "El correo electrónico ingresado ya está registrado. Ingrese otro.";
                span.className = "invalid";
                envio = false;
            }
            else{
                span.innerHTML = "Continúe con el ingreso de datos.";
                span.className = "valid";
                envio = true;
            }
        }
    }, false);
}, false);
 
form.addEventListener("submit", function(event){
    event.preventDefault();
    if (envio){
        this.submit();
    }
    else{
        alert("Debe de ingresar otro correo electrónico");
        input.value = "";
        input.focus();
    }
}, false);}, false); 
</script> 
  </head> 
  <link rel="stylesheet" type="text/css" href="Codigo.CSS">  
  <style type="text/css"> </style> 
  <body> 
  <form id = "datos" action = "registrar.php" method = "post"> 
    <label for = "correo">Ingrese su correo electrónico para suscribirse a nuestras noticias:</label> 
    <input type = "email" name = "correo" id = "correo" required /> 
    <span id = "mensaje"></span> 
    <input type = "submit" value = "Suscribirse" /> 
</form> 
  </body> 

</html> 

comprobar.php
Código PHP:
<?php
require_once("index.php");
$conexion mysqli_connect('localhost''root''123''dbjeison'); 
if (!
$conexion) exit(mysqli_connect_error()); 
$correo mysqli_real_escape_string($conexionstrip_tags(trim($_POST['correo']))); 
$consulta "SELECT correo FROM usuarios WHERE correo = '$correo'"
$resultados mysqli_query($conexion$consulta) or exit(mysqli_error()); 
//echo mysqli_num_rows($resultados) ? 'yes' : 'no'; 
if (mysqli_num_rows($resultados)>0){
    echo 
"el dato ya existe";
    exit(
0);
}else{
    include(
"registrar.php");
}
?>
registrar.php
Código PHP:
<?php
require_once("comprobar.php");
require_once(
"index.php");
$nom=$_POST["correo"];
echo 
"el correo es".$nom;
//exit(0);
$sql=$conexion->query("insert into usuarios ('$nom')");    
?>