0

I've got a problem with my headers, when i put this:

<a href='?p=Winkelmand&BID=".$row['BID']."&ProductID=".$row['ProductID']."&Actie=Vermeerderen'><span class='glyphicon glyphicon-plus'></span></a> 

In my code it starts giving me errors when i add something to my shopping cart...

this is the warning:

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\Snackbar\Design\Pages\Head.php:117) in C:\xampp\htdocs\Snackbar\System\Pages\Winkelmand.php on line 81

Line 117 in Head.php:

print("<td><a href='?p=Winkelmand&BID=".$row['BID']."&ProductID=".$row['ProductID']."&Actie=Vermeerderen'><span class='glyphicon glyphicon-plus'></span></a> ".$row['Aantal']);

Line 81 in Winkelmand.php:

header("Location: ?p=Producten");

The weird thing is when i remove the then it works just fine and sends me to the page i requested with the header...

Thanks in advance

Thimo Franken
  • 348
  • 4
  • 20

1 Answers1

1

You must be sure that no output can be tolerated before changing headers
Notice, Warning and Errors are also an output :)

Basically your problem that you are acceding to undefined index in your $row array I suggest to you to do a minimum of checking like this

<?php
$bid        = empty($row['BID'])        ? '' : $row['BID']      ;
$productId  = empty($row['ProductID'])  ? '' : $row['ProductID'];
$antal      = empty($row['Aantal'])     ? '' : $row['Aantal']   ;
print("<td><a href='?p=Winkelmand&BID=".$bid."&ProductID=".$productId."&Actie=Vermeerderen'><span class='glyphicon glyphicon-plus'></span></a> ".$antal);

?>
Halayem Anis
  • 7,654
  • 2
  • 25
  • 45