Ver Mensaje Individual
  #14 (permalink)  
Antiguo 26/01/2012, 22:21
demian_666
 
Fecha de Ingreso: octubre-2011
Mensajes: 11
Antigüedad: 12 años, 6 meses
Puntos: 0
Respuesta: validación de campos en base de datos

Cita:
Iniciado por geq Ver Mensaje
Es por el tipo de campo. Te había sugerido usar un campo INTEGER, en lugar de datetime para que el cálculo de la fecha sea mucho más sencillo (fijate que usando time() es sólo cuestión de restar segundos), así que deberías cambiar ese campo a INT para poder guardar el timestamp.

Saludos.
Sorry.... Ya cambie el tipo de campo a INT y el código quedo así:

Código PHP:
<?PHP
include("config2.php"); 
REQUIRE (
'conexion.php');
$fecha_limite=time()-24*60*60;
// connect to the mysql server
$link mysql_connect($server$db_user$db_pass)
or die (
"Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db($database)
or die (
"Could not select database because ".mysql_error());

// check if the folio is taken
$check "select id from $table where folio = '".$_POST['folio']."' and fecha<=$fecha_limite;"
$check "select id from $table where nombre = '".$_POST['nombre']."' and fecha<=$fecha_limite;";
$check "select id from $table where domicilio = '".$_POST['domicilio']."' and fecha<=$fecha_limite;";
$qry mysql_query($check)
or die (
"Could not match data because ".mysql_error());
$num_rows mysql_num_rows($qry); 
if (
$num_rows != 0) { 
echo 
"Lo siento, el folio, nombre y dirección ya existen en el sistema.<br>";
echo 
"<a href=registro_folio.php>Intenta con otro</a>";
exit; 
} else
$username=$_POST['username']; 
$fecha_insertado=$_POST['fecha_insertado'];
$hora_inicio=$_POST['hora_inicio'];
$ip=$_POST['ip'];
$vendedora=$_POST['vendedora'];
$zona=$_POST['zona'];
$nombre=$_POST['nombre'];
$apellidos=$_POST['apellidos'];
$direccion=$_POST['direccion'];
$exterior=$_POST['exterior'];
$interior=$_POST['interior'];
$domicilio=$direccion." #".$exterior." ".$interior;
$colonia=$_POST['colonia'];
$ciudad=$_POST['ciudad'];
$calle1=$_POST['calle1'];
$calle2=$_POST['calle2'];
$particular=$_POST['particular'];
$cantidad=$_POST['cantidad'];
$forma=$_POST['forma'];
$folio=$_POST['folio'];
$empresa=$_POST['empresa'];
$sorteo=$_POST['sorteo'];
$fventa=$_POST['fventa'];
$fenbol=$_POST['fenbol'];
$hvisita=$_POST['hvisita'];
$bvendidos=$_POST['bvendidos'];
$observaciones=$_POST['observaciones'];
$fecha=$_POST['fecha'];
$sql="INSERT INTO tbl_historico (username,fecha_insertado,hora_inicio,ip,vendedora,zona,nombre,apellidos,direccion,exterior,interior,domicilio,colonia,ciudad,calle1,calle2,particular,cantidad,forma,folio,empresa,sorteo,fventa,fenbol,hvisita,bvendidos,observaciones,fecha) VALUES ('".$username."','".$fecha."','".$hora_inicio."','".$ip."','".$vendedora."','".$zona."','".$nombre."','".$apellidos."','".$direccion."','".$exterior."','".$interior."','".$domicilio."','".$colonia."','".$ciudad."','".$calle1."','".$calle2."','".$particular."','".$cantidad."','".$forma."','".$folio."','".$empresa."','".$sorteo."','".$fventa."','".$fenbol."','".$hvisita."','".$bvendidos."','".$observaciones."',".time().")";
$resultado=mysql_query($sql,$conexion);
if (
$resultado)
{
    echo 
"<center><h1>!!REGISTRO ALMACENADO DE MANERA EXITOSA!!</h1><BR><img border=0 width=200 height=200 src=Imagenes/OK.png></center>"// MENSAJE QUE INFORMA QUE EL REGISTRO SE ALMACENO DE MANERA EXITOSA
}
else
    echo 
"<center><h1><font color=red>FALLO AL GUARDAR REGISTRO</font></h1></center>";    // MENSAJE QUE INFORMA QUE HUBO FALLO AL GUARDAR EL REGISTRO
?>
<!--SOLICITUD DEL ARCHIVO conexion.php QUE CONTIENE LA INFORMACIÓN PARA LA CONEXIÓN CON LA BASE DE DATOS -->
<!-- SE CAPTURAN LAS VARIABLES TRANSFERIDAS POR METODO POST Y SE INSERTAN EN LA BASE LLAMADA: CAC -->
<BR><BR>
<center><br><br><br><br><br>
    <div class="menu">
    <ul>
        <a href="menu.php" onclick="document.myForm.submit()"><img border=0 src="Imagenes/return.png"></a>
        </li>
    </ul>
    </div><!-- fin Menu -->        
<BR>
<BR><BR>
</form>
</body>
</html>
Guarda el dato fecha así: 1327637765

Pero aún permite duplicados...

Saludos y gracias!!