I have declared a variable $counter = 1;
and i have put a condition in else
condition. if $counter= 0;
. It should redirect to header("Location:" . BASE_URL . "product.php");
But i am getting a error as below!
Warning: Cannot modify header information - headers already sent by (output started at D:\wamp\www\project\ali\views\header.php:72) in D:\wamp\www\project\ali\products\check_out.php on line 125
Below is the code of check_out.php page!
<?php
require_once '../models/user.php';
require_once '../models/brand.php';
require_once '../models/cart.php';
//require_once '../models/item.php';
require_once '../views/top.php';
require_once '../models/place_order.php';
$counter = 1; // initial value
?>
</head>
<body>
<?php
if (!$obj_user->login) {
//redirect to the sign up page e.g
header("Location:" . BASE_URL . "signup.php");
}
?>
<div id="wrapper">
<?php
require_once '../views/header.php';
?>
<!-- **************************Main************************************ -->
<div id="main">
<div id="col-main">
<?php
require_once '../views/middle_left.php';
?>
<div id="middle-right">
<h3 class="text-center">Check Out</h3><hr>
<div class="row">
<div class="col-lg-12">
<h4>Billing Information</h4>
<span>Welcome <?php echo($obj_user->full_name); ?> Online Computer Shop</span>
</div>
</div>
<hr>
<div class="row">
<div class="col-lg-12">
<form class= "form-horizontal" action='" . BASE_URL . "products/process/process_cart.php' method='post'>
<div class="form-group">
<label class="col-sm-2 control-label" for="billing_name">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="billing_name" name="billing_name" value="" placeholder="Enter Name" >
<span id="billing_name_error">
<?php
if (isset($errors['billing_name'])) {
echo ($errors['billing_name']);
}
?>
</span>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="billing_address">Address</label>
<div class="col-sm-10">
<textarea class="form-control" id="billing_address" name="billing_address" value="" placeholder="Address"></textarea>
<span id="billing_address_error">
<?php
if (isset($errors['billing_address'])) {
echo ($errors['billing_address']);
}
?>
</span>
</div>
</div>
</form>
</div>
</div>
<hr>
<br>
<div class="shopping-background">
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<?php
if ($obj_cart->items)
{
echo("<form action='" . BASE_URL . "products/process/process_cart.php' method='post'>"
. "<table class='table table-hover' width='400px' border='1px' bordercolor='black' cellspacing='0' cellpadding='0'>");
echo("<thead>"
. "<tr align='center'>"
. "<th>Product Count</th>"
. "<th>Product Name</th>"
. "<th>Quantity</th>"
. "<th>TOTAL</th>"
. "</tr>"
. "</thead>");
foreach ($obj_cart->items as $item) {
echo("<tbody>"
. "<tr align='center'>"
. "<td>$counter</td>"
. "<td>$item->item_name</td>"
. "<td>$item->quantity</td>"
// . "<td><input class='box' type='text' value='$item->quantity' name='qtys[$item->itemID]'></td>"
. "<td>$item->total_price</td>"
. "</tr>"
. "</tbody>");
$counter++; // update counter value on each product
}
echo("<thead>"
. "<tr align='right' valign='middle'>"
. "<th></th>"
. "<th></th>"
. "<th></th>"
. "<th align='center'>$obj_cart->total_price</th>"
. "</tr>"
. "</thead>");
echo("</table></form>");
} else {
$counter == 0;
//echo("<label>Your cart is empty</label>");
header("Location:" . BASE_URL . "product.php");
}
?>
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
</div>
<hr>
<div class="row">
<div class="col-sm-3 col-sm-offset-2">
<a href="<?php echo(BASE_URL); ?>products/products.php"><input class='btn btn-default' type='button' value='Shop More' /></a>
</div>
<div class="col-sm-3 col-sm-offset-2">
<a href="<?php echo(BASE_URL); ?>"><input class='btn btn-default' type='button' value='Place Order' /></a>
</div>
<hr>
</div>
<br><br>
</div>
</div>
</div>
</div>
<!--***************************End of Main************************************ -->
<!-- ***************************Footer************************************ -->
<?php
require_once '../views/footer.php';
?>
<!-- *************************Footer************************************** -->
</body>
</html>