Ver Mensaje Individual
  #1 (permalink)  
Antiguo 11/07/2010, 11:00
jaivaman
 
Fecha de Ingreso: diciembre-2009
Mensajes: 16
Antigüedad: 16 años, 9 meses
Puntos: 1
validacion de campos distintos y comparacion con horas

Hola y ante todo gracias por contestar, estoy haciendo un formulario para insertar una materia en un horario el problema es el siguiente al querer hacer la comprobacion de un registro, no puedo lograr hacer que inserte un horario y ese mismo no lo repita o no me permita inserta uno que conicida con ese rango ejemplo:

dias ------lunes -- martes-- miercoles--- jueves---- viernes

horario01 9-11 ---------------9-11 ---------------- 9-11 -----sin problema

horario02 ------ ------- ------ -------- 12-13 -----------------sin problema

horario 03 9-11 ------- -------- ------- ------------------------- emplamado no dejarlo ins

horario 04 10-11 ----- 10-11 ------- ------ ---------------------emplamado no dejarlo ins

con la validacion que uso solo valida si todos los datos no coinciden, si solo conicide uno si lo deja insertar y se suponde que no deberia dejar insertar si uno coincide o se trunca entre horas,

esto es lo que estoy usando en mi tabla
que uso es esta :

Código:
CREATE TABLE `horarioins` (
  `usuario` double default NULL,
  `horarioN` double default NULL,
  `Lu` varchar(255) default NULL,
  `Ma` varchar(255) default NULL,
  `mi` varchar(255) default NULL,
  `Ju` varchar(255) default NULL,
  `Vi` varchar(255) default NULL,
  ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Código PHP:
<?php
$hostname_otono2003 
= "localhost";
$database_otono2003 = "20103";
$username_otono2003 = "adm";
$password_otono2003 = "";
$otono2003 = mysql_pconnect($hostname_otono2003, $username_otono2003, $password_otono2003) or trigger_error(mysql_error(),E_USER_ERROR); 

if (!
function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset(
$_SERVER['QUERY_STRING'])) {
  
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

$var1_Recordset1 = "none";
if (isset(
$_POST['Lu'])) {
  
$var1_Recordset1 = $_POST['Lu'];
}
$var2_Recordset1 = "none";
if (isset(
$_POST['Ma'])) {
  
$var2_Recordset1 = $_POST['Ma'];
}
$var3_Recordset1 = "none";
if (isset(
$_POST['mi'])) {
  
$var3_Recordset1 = $_POST['mi'];
}
$var4_Recordset1 = "none";
if (isset(
$_POST['Ju'])) {
  
$var4_Recordset1 = $_POST['Ju'];
}
$var5_Recordset1 = "none";
if (isset(
$_POST['Vi'])) {
  
$var5_Recordset1 = $_POST['Vi'];
}
mysql_select_db($database_otono2003, $otono2003);
$query_Recordset1 = sprintf("SELECT usuario, horarioN, Lu, Ma, mi, Ju, Vi FROM `horario-test`  WHERE  Lu = %s AND  Ma  = %s AND mi  = %s AND Ju  = %s AND Vi  = %s ", GetSQLValueString($var1_Recordset1, "text"),GetSQLValueString($var2_Recordset1, "text"),GetSQLValueString($var3_Recordset1, "text"),GetSQLValueString($var4_Recordset1, "text"),GetSQLValueString($var5_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $otono2003) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

$comprobar = false;
if (
$totalRows_Recordset1  >0) {
$comprobar = true;
}
else {
if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL = sprintf("INSERT INTO `horario-test` (usuario, horarioN, Lu, Ma, mi, Ju, Vi) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['usuario'], "double"),
                       
GetSQLValueString($_POST['horarioN'], "text"),
                       
GetSQLValueString($_POST['Lu'], "text"),
                       
GetSQLValueString($_POST['Ma'], "text"),
                       
GetSQLValueString($_POST['mi'], "text"),
                       
GetSQLValueString($_POST['Ju'], "text"),
                       
GetSQLValueString($_POST['Vi'], "text"));

  
mysql_select_db($database_otono2003, $otono2003);
  
$Result1 = mysql_query($insertSQL, $otono2003) or die(mysql_error());

  
$insertGoTo = "insertado.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s", $insertGoTo));
}
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body><?php if($_POST && $comprobar){
echo 
'<p class="advertencia">'.$_POST['Lu'].' ' .$_POST['Ma'].' ' .$_POST['mi'].' ' .$_POST['Ju'].' ' .$_POST['Vi'].'ya esta registrado </p>' ;
}
?>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  <table align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Usuario:</td>
      <td><input type="text" name="usuario" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">HorarioN:</td>
      <td><input type="text" name="horarioN" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Lu:</td>
      <td><input type="text" name="Lu" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Ma:</td>
      <td><input type="text" name="Ma" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Mi:</td>
      <td><input type="text" name="mi" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Ju:</td>
      <td><input type="text" name="Ju" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Vi:</td>
      <td><input type="text" name="Vi" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><input type="submit" value="Insertar registro" /></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1" />
</form>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result
($Recordset1);
?>
Espero su ayuda gracias!!!!