-2

I am getting following warning when i click on hyperlink. I followed solution given in this link: How to fix "Headers already sent" error in PHP But i can't get my code work. It still gives me the warning and does not redirect to next page i.e given in remove_from_cart.php.Any suggestions please.

Warning: Cannot modify header information - headers already sent by (output started at D:\index.php:188) in D:\remove_from_cart.php on line 4

Code

<a href="index.php?page=remove_from_cart&action=remove&id=<?php echo $row['productid']; ?>">X</a>

remove_from_cart.php

<?php
$id = isset($_GET['id']) ? $_GET['id'] : "";
unset($_SESSION['cart'][$id]);
header('Location: index.php?page=cart&id='.$id  );
?>
Community
  • 1
  • 1
tabia
  • 631
  • 2
  • 10
  • 33

1 Answers1

0

change this

echo "Removed id:".$id;//you cannot echo here
header('Location: index.php'  );

to

header('Location: index.php?id='.$id  );
exit();// good practice to exit after header().
Niranjan N Raju
  • 12,047
  • 4
  • 22
  • 41