php error
2 posts
Page 1 of 1
Hello,
Can anyone help me please i just got this error
1 Warning: Cannot modify header information - headers already sent by (output started at /customers/2/e/7/yansumkune.com/httpd.www/cart.php:20) in /customers/2/e/7/yansumkune.com/httpd.www/cart.php on line 22
This is the code for this cart.php
PHP Code:
<?php
session_start();
//session_destroy();
require('scripts/connect.php');
function display_cart(){
global $dbc;
$q = mysql_query("SELECT `id`, `image`, `name`, `desc`, `price` FROM cart WHERE `quantity` > 0");
$num = mysql_num_rows($q);
while($fetch = mysql_fetch_assoc($q)){
echo '<img src="pics/'.$fetch['image'].'" width="120" height="120" /><br /><span id="name">'.$fetch['name'].'</span><br/>'.$fetch['desc'].'<br/> $ '.$fetch['price'].' <a href="cart.php?add='.$fetch['id'].'">Add to Cart</a><br/><br/>';
}
}
if(isset($_GET['add']) && !empty($_GET['add'])){
$id = $_GET['add'];
$q = mysql_query("SELECT `id`, `quantity` FROM cart WHERE `id`= '".$id."'");
while($quantity = mysql_fetch_assoc($q)){
if($quantity['quantity'] != @$_SESSION['cart_'.$id]){
echo @$_SESSION['cart_'.$id]+=1;
}
header('Location:products.php');
}
}
if(isset($_GET['remove'])){
$_SESSION['cart_'.$_GET['remove']]--;
header('Location:products.php');
}
if(isset($_GET['delete'])){
$_SESSION['cart_'.$_GET['delete']]=0;
header('Location:products.php');
}
function product(){
foreach($_SESSION as $name => $value){
if($value > 0){
if(substr($name,0,5) == 'cart_'){
$id = substr($name,5,(strlen($name-5)));
$q = mysql_query("SELECT `id`, `shipping`, `name`, `price` FROM cart WHERE `id` = '".$id ."'");
while($get = mysql_fetch_assoc($q)){
$total = $value * $get['price'];
echo $get['name'].'X'.$value.'@'.$get['price'].'=$ '.$total.'<a href="cart.php?add='.$id.'"> [+] </a><a href="cart.php?remove='.$id.'"> [-] </a><a href="cart.php?delete='.$id.'"> [Delete] </a><br /><br />';
}
}
}
}
}
?>
can anyone help me with this error please?
Can anyone help me please i just got this error
1 Warning: Cannot modify header information - headers already sent by (output started at /customers/2/e/7/yansumkune.com/httpd.www/cart.php:20) in /customers/2/e/7/yansumkune.com/httpd.www/cart.php on line 22
This is the code for this cart.php
PHP Code:
<?php
session_start();
//session_destroy();
require('scripts/connect.php');
function display_cart(){
global $dbc;
$q = mysql_query("SELECT `id`, `image`, `name`, `desc`, `price` FROM cart WHERE `quantity` > 0");
$num = mysql_num_rows($q);
while($fetch = mysql_fetch_assoc($q)){
echo '<img src="pics/'.$fetch['image'].'" width="120" height="120" /><br /><span id="name">'.$fetch['name'].'</span><br/>'.$fetch['desc'].'<br/> $ '.$fetch['price'].' <a href="cart.php?add='.$fetch['id'].'">Add to Cart</a><br/><br/>';
}
}
if(isset($_GET['add']) && !empty($_GET['add'])){
$id = $_GET['add'];
$q = mysql_query("SELECT `id`, `quantity` FROM cart WHERE `id`= '".$id."'");
while($quantity = mysql_fetch_assoc($q)){
if($quantity['quantity'] != @$_SESSION['cart_'.$id]){
echo @$_SESSION['cart_'.$id]+=1;
}
header('Location:products.php');
}
}
if(isset($_GET['remove'])){
$_SESSION['cart_'.$_GET['remove']]--;
header('Location:products.php');
}
if(isset($_GET['delete'])){
$_SESSION['cart_'.$_GET['delete']]=0;
header('Location:products.php');
}
function product(){
foreach($_SESSION as $name => $value){
if($value > 0){
if(substr($name,0,5) == 'cart_'){
$id = substr($name,5,(strlen($name-5)));
$q = mysql_query("SELECT `id`, `shipping`, `name`, `price` FROM cart WHERE `id` = '".$id ."'");
while($get = mysql_fetch_assoc($q)){
$total = $value * $get['price'];
echo $get['name'].'X'.$value.'@'.$get['price'].'=$ '.$total.'<a href="cart.php?add='.$id.'"> [+] </a><a href="cart.php?remove='.$id.'"> [-] </a><a href="cart.php?delete='.$id.'"> [Delete] </a><br /><br />';
}
}
}
}
}
?>
can anyone help me with this error please?
the problem is this line:
Also just an advice, stop using the @ error handler, because it has a very big impact on performance.
Code: Select all
For some reason your code outputs something before the headers are sent. Headers are very tricky. If you want to change them, you must do so before anything is outputted. Or you can just buffer the entire page and then do whatever you want to the headers with no problem. Look up ob_start function and try not to abuse it, as it slows down the page loading time.header('Location:products.php');
Also just an advice, stop using the @ error handler, because it has a very big impact on performance.
You can find me on Facebook or on Skype mihai_92b
2 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023