I got some JQuery codes to verify if any value ( cedula in this case) exists in the database.
The system works well, it shows when the card value exists or not, I would like now to prevent the form from being sent, because although it says that it CAN NOT be used because it already exists, it sends the data, and as it is already that stored cedula does not insert.
Registration.php
<?php
include "conexion.php";
?>
<!doctype html>
<html>
<head>
<link href="styles.css" media="screen" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery-1.3.2.js"></script>
<meta charset="utf-8">
<title> </title>
</head>
<body>
<script type="text/javascript">
$(document).ready(function() {
$('#cedula').blur(function(){
$('#info').html('<img src="loader.gif" alt="" />').fadeOut(300);
var cedula = $(this).val();
var dataString = 'cedula='+cedula;
$.ajax({
type: "POST",
url: "comprobar_disponibilidad.php",
data: dataString,
success: function(data) {
$('#info').fadeIn(300).html(data);
}
});
});
});
</script>
<h1 align ="center">Bienvenido</h1>
<a href ="index.html"><ol>Pagina Principal</ol></a>
<a href ="registrar.php"><ol>Registrar</ol></a>
<a href ="listado.php"><ol>Listado</ol></a>
<a href ="Sancion.php"><ol>Sancion</ol></a>
<form method="POST" action ="procesar.php">
<div>
<label> Ingrese su cedula </label>
<input type="text" id="cedula" name="cedula">
<div id="info"></div>
</div>
<label> Ingrese su primer nombre </label>
<input type="text" id="nombre1" name="nombre1"><br/>
<label> Ingrese su segundo nombre </label>
<input type="text" id="nombre2" name="nombre2"><br/>
<label> Ingrese su primer apellido </label>
<input type="text" id="apellido1" name="apellido1"><br/>
<label> Ingrese su segundo apellido </label>
<input type="text" id="apellido2" name="apellido2"><br/>
<label> Ingrese su rango </label>
<div><select name="rango">
<?php
global $cone;
$registros=mysqli_query($cone,"select * from rangos");
while ($reg = mysqli_fetch_array($registros))
echo "<option value='$reg[id_rango]'>".$reg[rango]."</option>";
?>
</select></div>
<input type="submit" value="enviar">
</form>
</body>
</html>
Check_availability.php
<?php
sleep(1);
require_once'conexion.php';
global $cone;
if($_REQUEST) {
$cedula = $_REQUEST['cedula'];
$sql="Select * from personal where cedula = '$cedula'";
if ($result=mysqli_query($cone,$sql))
{
// Return the number of rows in result set
$rowcount=mysqli_num_rows($result);
//printf("Result set has %d rows.\n",$rowcount); mostrar resultado
if($rowcount > 0)
echo '<div id="Error">Cedula ya registrada</div>';
else
echo '<div id="Success">Disponible</div>';
}
}
?>