Problem with header and foreach (headers already sent by) [duplicate]

0

I have a problem with a form in which I have several checkboxes. This is so they can choose various services.

The checkboxes have as value the fields id_del_servicio,id_de_descuento together. This is so that later in the PHP, with a foreach, it separates them and inserts them in their respective fields.

The problem is when I'm online: the header sends an error to the foreach that are empty. That is, services that were not selected and obviously does not direct me.

Warning: Cannot modify header information - headers already sent by (output started
<?php
foreach(($_POST['horno']) &horno  as $horno){
    //$horno1=$horno[0];
    //$horno2=$horno[1];        
};

foreach($_POST['refrigerador'] as $ref){
    //$ref1=$ref[0];
    //$ref2=$ref[1];        
};

foreach($_POST['ventanas'] as $ven){
    //$ven1=$ven[0];
    //$ven2=$ven[1];        
};

foreach($_POST['lavado'] as $lav){
    //$lav1=$lav[0];
    //$lav2=$lav[1];        
};

foreach($_POST['planchar'] as $pla){
    //$pla1=$pla[0];
    //$pla2=$pla[1];        
};

foreach($_POST['hogars'] as $hog){
    //$hog1=$hog[0];
    //$hog2=$hog[1];        
};

$user=$_POST['Usuario'];
$cliente = (int)$user; 
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "call sp_segundopaso_servicio('.$cliente.','.$horno[0].','.$horno[1].','.$ref[0].','.$ref[1].','.$ven[0].','.$ven[1].','.$lav[0].','.$lav[1].','.$pla[0].','.$pla[1].','.$hog[0].','.$hog[1].')";
if ($conn->query($sql) === TRUE) {

   header('Location: ../domicilio.php');

} else {

}
$conn->close();

?>
    
asked by Sistemas MKT 24.05.2016 в 00:50
source

2 answers

1

Before the header () there can be no output, (not even a warning) just the part of the most important message you did not put (output started ... , there tells you in which part of the script you are generating a previous output to the header

Sometimes to avoid these messages you just have to use an @ on the line, for example

<?php
$fp = @ fopen( '/etc/shadow', 'r' );
if ( $fp === FALSE )
{
  header( 'Location: /acaVanLosMalos.html' );
}
    
answered by 24.05.2016 в 01:44
0

Try passing an absolute path to the header, if this does not work you can always use this alternative:

    echo '<meta http-equiv="refresh" content="0; url=tu_pagina.php">';

I hope it will be helpful, greetings.

    
answered by 24.05.2016 в 00:56