Ver Mensaje Individual
  #1 (permalink)  
Antiguo 20/11/2013, 06:20
Avatar de dianali_1990
dianali_1990
 
Fecha de Ingreso: noviembre-2013
Mensajes: 11
Antigüedad: 10 años, 5 meses
Puntos: 0
Exclamación me sale error en esta validacion

tengo este formulario
Código HTML:
<table width="358" border
  ="0">
    <tr>
      <td width="447"><table width="347" height="209" border="2" class="fieldContainer">
        <tr>
          <td width="335"><div align="center" class="fieldContainer">CAPTURA DE LECTURAS</div></td>
          </tr>
        <tr>
          <td height="178"><table width="340" height="108" border="0">
            <tr>
              <td width="136" height="26" class="label"><label for="id_var">Variable:</label></td>
              <td width="194"><select name="var" size="1" class="field" id="var">
                <option value="">Selecciona</option>
                <?php  
do {  
?>
                <option value="<?php echo $row_variables['id_variable']?>"><?php echo $row_variables['nom_var']?></option>
                <?php
} while ($row_variables = mysql_fetch_assoc($variables));
  $rows = mysql_num_rows($variables);
  if($rows > 0) {
      mysql_data_seek($variables, 0);
	  $row_variables = mysql_fetch_assoc($variables);
  }
?>
                </select></td>
              </tr>
            <tr>
              <td class="label"><label for="fecha_lectura">Lectura:</label></td>
              <td><span class="field">
                <input type="text" name="lectura" id="lectura" />
                </span></td>
              </tr>
            <tr>
              <td class="label"><label for="fecha_lectura">Fecha Lectura:</label></td>
              <td><span class="field">
               <?php
$date =date("Y/m/j");
?>
                <input name="fecha" type="text" id="fecha"  size="10" />
                </span></td>
              </tr>
            <tr>
              <td class="label"><label for="fecha_lectura">Hora de captura:</label></td>
              <td><span class="field">
                <input type="text" name="hora" id="hora" />
                </span></td>
              </tr>
            </table>
            <label for="Selecciona Variable"> </label>
            <div align="center"><span class="signupButton" >
              <input type="submit" name="submit" id="submit" value="Guardar" />
            </span></div></td>
          </tr>
      </table></td>
      > </tr>
  </table>
</div>
<div align="center"></div>
<p align="center">&nbsp;</p> 
y este codigo muestra los registros capturados
Código PHP:
  <?php  
  $link 
= @mysql_connect("localhost""root","")
      or die (
"Error al conectar a la base de datos.");
  @
mysql_select_db("bdaq"$link)
      or die (
"Error al conectar a la base de datos.");
  
$query "SELECT lectura, fecha_lectura,hora_lectura " .
      
"FROM lectura " .
      
"WHERE lectura.id_variable = 1"
       
;
 
$resultmysql_query($query) or die(mysql_error());
if(
mysql_num_rows($result)==0) die("No hay registros para mostrar");
  
$numero 0;
  while(
$row mysql_fetch_array($result))
  {
    echo 
"<tr><td width=\"25%\"><font face=\"verdana\">" 
        
$row["lectura"] . "</font></td>";
    echo 
"<td width=\"25%\"><font face=\"verdana\">" 
        
$row["fecha_lectura"] . "</font></td>";
    echo 
"<td width=\"25%\"><font face=\"verdana\">" 
        
$row["hora_lectura"] . "</font></td>";
    echo 
"<td width=\"25%\"><font face=\"verdana\">" 
      
"</font></td></tr>";    
    
$numero++;
  }
  echo 
"<tr><td colspan=\"15\"><font face=\"verdana\"><b>Número total de registros: " $numero 
      
"</b></font></td></tr>";
  
  
mysql_free_result($result);
  
mysql_close($link);
?>
como podria hacer la validacion donde dice hora no se inserte la misma en una fecha determinada
digamos que guardo en la fecha 20/11/13 en la hora 00:00:00
me gustaria que mandara un mensaje para evitar que se dupliquen los datos si quieren ingresar un dato en la misma fecha y hora, y que ademas solo me muestre de los datos mas reciente digamos que solo los que capture "HOY"


y tengo este otro codigo que deberia validar el registro pero no me guarda nada
Código PHP:
<?php
require_once('conexion.php');
?>
<body>

<?php 

$var
="'".$_POST["var"]."'";
$lectura="'".$_POST["lectura"]."'"
$fecha="'".$_POST["fecha"]."'"
$hora="'".$_POST["hora"]."'"

if ((
$var=="''") or ($lectura=="''") or ($fecha=="''") or ($hora=="''")){
    
?>
echo "<script languaje='javascript'>alert('FALTAN CAMPOS POR LLENAR'); location.href = 'pronosticos.php';</script>";
    </script> 

<?php    
}else{         
mysql_select_db($database_bdaq$aq);
mysql_query("INSERT INTO lecturas(id_variable,lecturas,fecha_lectura,hora_lectura) VALUES ($var,$lectura,$fecha,$hora)",$bda);
?>
echo "<script languaje='javascript'>alert('Registro Exitoso'); location.href = 'pronostico.php';</script>";

</script>             
<?php
}

?>
espero me puedan auxiliar!!