realizo un formulario que corresponde a un horario de trabajadores. Mi formulario inserta los días y las horas sin problema alguno, lo que necesito o pretendo que haga el sistema es que revise en mi BD los registros que se encuentren y muestre una alerta que ese registro ya existe, esto ultimo quiero que se base en todos mis campos idctg_turno,idctg_dia, hr_entrada y hr_salida es decir si ya existe el dia registrado "lunes" con hora entrada 06:00am, hora Salida 03:00 pm y mi Turno "Primero", no inserte el registro por que ya se encuentra en mi BD y que mande un mensaje.
Muchas Gracias/Saludos
<html lang="es">
<head>
<style>
div label
{
float: left;
width: 50%;
}
</style>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-theme.min.css" rel="stylesheet">
<!-- FooTable Bootstrap CSS -->
<link href="js/compiled/footable.bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/docs.css" rel="stylesheet">
<script src="js/demo-rows.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-theme.css" rel="stylesheet">
<script src="js/jquery-3.1.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<div id="page">
<div class="header">
<a href="#menu"></a>
Sistema Integral de Nómina
</div>
<h1 align="center">Gestión de Horarios</h1>
<p> <strong>Consulta de Horarios</strong>
<a href="horario_edit.php" ><img src="images/file_get.png" width="50" height="50" title="consultar" style="cursor:pointer"></a></p>
<div class="container">
<div class="row">
<h3 style="text-align:center">NUEVO REGISTRO DE HORARIO</h3>
</div>
<form class="form-horizontal" method="POST" action="guardar.php" autocomplete="off">
<div class="form-group">
<label for="idctg_turno" class="col-sm-2 control-label">Turno</label>
<?php
require("connect_db.php");
$query = "SELECT DISTINCT idctg_turno, descripcion FROM ctg_turno";
$res = $mysqli->query($query);
$option = '';
while ($row = $res->fetch_assoc()){
$option.="<option value=\"$row[idctg_turno]\">$row[descripcion] </option>";
}
?>
<div class="col-sm-10">
<select type="text" class="form-control" id="idctg_turno" name="idctg_turno" placeholder="Turno" required >
<option value="-">Selecciona el Turno</option>
<?php echo $option; ?>
</select><br /><br /></div></div>
<div class="form-group">
<label for="idctg_dia" class="col-sm-2 control-label">Día</label>
<div class="col-sm-10">
<label class="checkbox-inline">
<input type="checkbox" id="idctg_dia[]" name="idctg_dia[]" value="1"> Lunes
</label>
</div>
</div>
<div class="form-group">
<label for="hr_entrada" class="col-sm-2 control-label">Hora Entrada</label>
<div class="col-sm-10">
<input type="time" class="form-control" id="hr_entrada" name="hr_entrada[]" placeholder="hr_entrada">
</div>
</div>
<div class="form-group">
<label for="hr_salida" class="col-sm-2 control-label">Hora Salida</label>
<div class="col-sm-10">
<input type="time" class="form-control" id="hr_salida" name="hr_salida[]" placeholder="hr_salida">
</div>
</div><br /><br />
<div class="form-group">
<label for="idctg_dia" class="col-sm-2 control-label">Día</label>
<div class="col-sm-10">
<label class="checkbox-inline">
<input type="checkbox" id="idctg_dia[]" name="idctg_dia[]" value="2"> Martes
</label>
</div>
</div>
<div class="form-group">
<label for="hr_entrada" class="col-sm-2 control-label">Hora Entrada</label>
<div class="col-sm-10">
<input type="time" class="form-control" id="hr_entrada" name="hr_entrada[]" placeholder="hr_entrada">
</div>
</div>
<div class="form-group">
<label for="hr_salida" class="col-sm-2 control-label">Hora Salida</label>
<div class="col-sm-10">
<input type="time" class="form-control" id="hr_salida" name="hr_salida[]" placeholder="hr_salida">
</div>
</div><br /><br />
<div class="form-group">
<label for="idctg_dia" class="col-sm-2 control-label">Día</label>
<div class="col-sm-10">
<label class="checkbox-inline">
<input type="checkbox" id="idctg_dia[]" name="idctg_dia[]" value="3"> Miercoles
</label>
</div>
</div>
<div class="form-group">
<label for="hr_entrada" class="col-sm-2 control-label">Hora Entrada</label>
<div class="col-sm-10">
<input type="time" class="form-control" id="hr_entrada" name="hr_entrada[]" placeholder="hr_entrada">
</div>
</div>
<div class="form-group">
<label for="hr_salida" class="col-sm-2 control-label">Hora Salida</label>
<div class="col-sm-10">
<input type="time" class="form-control" id="hr_salida" name="hr_salida[]" placeholder="hr_salida">
</div>
</div><br /><br />
<div class="form-group">
<label for="idctg_dia" class="col-sm-2 control-label">Día</label>
<div class="col-sm-10">
<label class="checkbox-inline">
<input type="checkbox" id="idctg_dia[]" name="idctg_dia[]" value="4"> Jueves
</label>
</div>
</div>
<div class="form-group">
<label for="hr_entrada" class="col-sm-2 control-label">Hora Entrada</label>
<div class="col-sm-10">
<input type="time" class="form-control" id="hr_entrada" name="hr_entrada[]" placeholder="hr_entrada">
</div>
</div>
<div class="form-group">
<label for="hr_salida" class="col-sm-2 control-label">Hora Salida</label>
<div class="col-sm-10">
<input type="time" class="form-control" id="hr_salida" name="hr_salida[]" placeholder="hr_salida">
</div>
</div><br /><br />
<div class="form-group">
<label for="idctg_dia" class="col-sm-2 control-label">Día</label>
<div class="col-sm-10">
<label class="checkbox-inline">
<input type="checkbox" id="idctg_dia[]" name="idctg_dia[]" value="5"> Viernes
</label>
</div>
</div>
<div class="form-group">
<label for="hr_entrada" class="col-sm-2 control-label">Hora Entrada</label>
<div class="col-sm-10">
<input type="time" class="form-control" id="hr_entrada" name="hr_entrada[]" placeholder="hr_entrada">
</div>
</div>
<div class="form-group">
<label for="hr_salida" class="col-sm-2 control-label">Hora Salida</label>
<div class="col-sm-10">
<input type="time" class="form-control" id="hr_salida" name="hr_salida[]" placeholder="hr_salida">
</div>
</div><br /><br />
<div class="form-group">
<label for="idctg_dia" class="col-sm-2 control-label">Día</label>
<div class="col-sm-10">
<label class="checkbox-inline">
<input type="checkbox" id="idctg_dia[]" name="idctg_dia[]" value="6"> Sabado
</label>
</div>
</div>
<div class="form-group">
<label for="hr_entrada" class="col-sm-2 control-label">Hora Entrada</label>
<div class="col-sm-10">
<input type="time" class="form-control" id="hr_entrada" name="hr_entrada[]" placeholder="hr_entrada">
</div>
</div>
<div class="form-group">
<label for="hr_salida" class="col-sm-2 control-label">Hora Salida</label>
<div class="col-sm-10">
<input type="time" class="form-control" id="hr_salida" name="hr_salida[]" placeholder="hr_salida">
</div>
</div><br /><br />
<div class="form-group">
<label for="idctg_dia" class="col-sm-2 control-label">Día</label>
<div class="col-sm-10">
<label class="checkbox-inline">
<input type="checkbox" id="idctg_dia[]" name="idctg_dia[]" value="7"> Domingo
</label>
</div>
</div>
<div class="form-group">
<label for="hr_entrada" class="col-sm-2 control-label">Hora Entrada</label>
<div class="col-sm-10">
<input type="time" class="form-control" id="hr_entrada" name="hr_entrada[]" placeholder="hr_entrada">
</div>
</div>
<div class="form-group">
<label for="hr_salida" class="col-sm-2 control-label">Hora Salida</label>
<div class="col-sm-10">
<input type="time" class="form-control" id="hr_salida" name="hr_salida[]" placeholder="hr_salida">
</div>
</div><br /><br />
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<a href="index.php" class="btn btn-default">Regresar</a>
<button type="submit" class="btn btn-primary">Guardar</button>
</div>
</div>
</form>
</div>
<?php
include("includes/menus.php"); ?>
</div>
<!-- Placed at the end of the document so the pages load faster -->
<!--<script src="includes/jquery-1.9.1.min.js"></script>-->
<script src="js/bootstrap/js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="js/ie10-viewport-bug-workaround.js"></script>
<!-- Add in any FooTable dependencies we may need -->
<script src="js/moment.min.js"></script>
<!-- Add in FooTable itself -->
<script src="js/compiled/footable.js"></script>
<!-- Initialize FooTable -->
<script>
jQuery(function($){
$('.table').footable();
});
</script>
</body>
</div>
</html>
<?php
$turno = $_POST['idctg_turno'];
$entrada = $_POST['hr_entrada'];
$salida =$_POST['hr_salida'];
$arraydia = $_POST['idctg_dia'];
$total = count($arraydia);
$mysqli = new mysqli("localhost", "root", "", "admon");
if ($stmt = $mysqli->prepare("INSERT INTO ctg_horario (idctg_turno, hr_entrada, hr_salida, idctg_dia) VALUES (?,?,?,?)")) {
for ($i=0; $i < $total ; $i++) {
//Como envía todos los valores, preguntamos si
// no está vacío entonces insertamos.
if(!empty($entrada[$i]) && !empty($salida[$i])){
$in = date('H:i:s',strtotime($entrada[$i]));
$out = date('H:i:s',strtotime($salida[$i]));
//bindeamos los parámetros para la query
// Obteniendo el elemento del array idctg_dia
$stmt->bind_param("ssss", $turno, $in, $out,$arraydia[$i]);
$stmt->execute();
}
}
}
?>
<html lang="es">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-theme.css" rel="stylesheet">
<script src="js/jquery-3.1.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="row" style="text-align:center">
<?php if($stmt) { ?>
<h3>REGISTRO GUARDADO</h3>
<?php } else { ?>
<h3>ERROR AL GUARDAR</h3>
<?php } ?>
<a href="horario.php" class="btn btn-primary">Regresar</a>
</div>
</div>
</div>
</body>
</html>