Why this error comes up: Uninitialized string offset: 1 in line 13

0

<?php

 require("connect_db.php");
 
 
 
 

     foreach($_POST['idctg_dia'] as $index => $value) {
    // $value tendrá valor desde 1 (lunes) hasta 7 (domingo)
    $entrada = $_POST['hr_entrada'][$index];
    $salida = $_POST['hr_salida'][$index];
	$turno = $_POST['idctg_turno'][$index];
    // Aquí debes validar los datos antes de agregarlos a una consulta
	
	
    if ($stmt = $mysqli->prepare("INSERT INTO ctg_horario (idctg_dia, hr_entrada, hr_salida, idctg_turno) values ('$turno','$entrada','$salida', 'idctg_turno')")) {
		$turno = $_POST['idctg_turno'];
		$entrada = $_POST['hr_entrada'];
		$salida = $_POST['hr_salida'];
		
		if($stmt->execute()){		
			 echo '<script>alert("Datos Ingresados Correctamente")</script> ';
        }
    }
}
?>

<html>

<head>

<form action="" method=post name="formulario">


<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>
</head>

<body>
		<div id="page">
			<div class="header">
				<a href="#menu"></a>
				Sistema Integral de Nómina
			</div>
			<h1 align="center">Gesti&oacute;n de Nómina</h1>
            <p align="center"><br /><input type="submit"  name="botonGuardar"class="bg-primary" value="Agregar"  /></p>
            <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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>

<title>Gesti&oacuten de Nómina</title>



<body>





<center><fieldset style="width:40%" "width:900px">




<legend >Registro de Nómina</legend>
<td>
	
	
		  
<th><label>Selecciona el Turno:</label>
<table>

<?php
require("connect_db.php");

$query = "SELECT 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>";   
   
}
?>

<select name="idctg_turno">
<option value="-">Selecciona el Turno</option>
<?php echo $option; ?>
</select><br /><br />




               <tr>
          <th><input type="checkbox" value="1" name="idctg_dia[]"> Lunes</th>
               <th>Hora Entrada
                 <input type="time" name="hr_entrada[]">
               </th>
               <th>Hora Salida
                  <input type="time" name="hr_salida[]">
          </th></tr>
          <tr>
          <th><input type="checkbox" value="2" name="idctg_dia[]"> Martes</th>
               <th>Hora Entrada
                 <input type="time" name="hr_entrada[]">
               </th>
               <th>Hora Salida
                  <input type="time" name="hr_salida[]">
          </th></tr>
			   
			   
			   
			    
			   
			   
			    

			   
			   
			   
			   
			   
			   
			   
		 
		
			   
								
  
  
	 
	
</td></table><center></fieldset><br></br>





</form>





   

    </html>
    
asked by Oscar_DR 17.02.2018 в 08:54
source

1 answer

0

I understand that your problem is not an error, but it is marked with Notice that this indicates possible problems of code that at first sight you would not detect, access to undefined variables, empty, etc. It seems to me that your problem is derived that the first time you load the page you do not have $ _POST and in the first loop you are accessing said variable assuming that it always has values.

foreach($_POST['idctg_dia'] as $index => $value) {

At no time do you verify that $ _POST ['idctg_dia'] is available

    
answered by 17.02.2018 в 09:49