Results 1 to 5 of 5

Thread: [RESOLVED] php error help please

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Resolved [RESOLVED] php error help please

    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?
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: php error help please

    Quote Originally Posted by Jamie_Garland View Post
    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

    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?
    You should use the header() functions before outputting anything. I mean before you do any echo statement.

    Check the higlighted line. You are echoing that value and then you are calling the header() function! Either move that header() function before that IF condition or comment that echo statement!


    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: php error help please

    Hello,

    Thank resolved that issue.

    when i try to use a £ sign it gives me some silly simple like the screenshot below can this be fixes?.

    Name:  Capture.JPG
Views: 68
Size:  19.5 KB

    this is the code

    PHP Code:
     if($net_payment == 0){
                echo 
    "Your Shopping Cart Is Empty!.";
            } else{
                echo 
    "Total = £".$net_payment.'<br />';
            }
        } 
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  4. #4
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: php error help please

    Try adding this meta tag in your HTML page's header block:

    Code:
    <meta charset="utf-8" />
    If your problem is resolved, mark the thread as RESOLVED. This will make others know that the question is resolved and they can save time.
    Also, do RATE the posts that you find as helpful. Rating the posts is gesture for showing your appreciation on the help we offer.


    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: php error help please

    hello,
    that didnt work.

    ive also mennt to post code for my shopping cart i have it working but i cant get the checkout to work it keeps saying it empty when i press the paypal button van you help please?.

    ill do the rating aswell.

    This is cart.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)){
                header('Location:products.php');
                if($quantity['quantity'] != @$_SESSION['cart_'.$id]){
                    echo @$_SESSION['cart_'.$id]+=1;
                }
            }
        }
        
        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 paypal_item(){
          $num=0;
            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_row = mysql_fetch_assoc($q)){  
                              $num++;
                              echo '<input type="hidden" name="item_number_'.$num.'" value="'.$id.'">';
                              echo '<input type="hidden" name="item_name_'.$num.'" value="'.$get_row['name'].'">';
                              echo '<input type="hidden" name="amout_'.$num.'" value="'.$get_row['price'].'">'; 
                              echo '<input type="hidden" name="shipping_'.$num.'" value="'.$get_row['shipping'].'">';
                              echo '<input type="hidden" name="quantity_'.$num.'" value="'.$value.'">';        
        }
            }
            }
            }
        }
        
        function product(){
            $net_payment=0;
            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 />';
                        }
                    }
                        $net_payment+=$total;
                }
            }
            if($net_payment == 0){
                echo "Your Shopping Cart Is Empty!.";
            } else{
                echo "Total = £".$net_payment.'<br /><br />';
                ?>
                
                <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
                    <input type="hidden" name="cmd" value="_cart">
                    <input type="hidden" name="business" value="mark@mbdues.co.uk">
                    <input type="hidden" name="upload" value="1">
                    <?php paypal_item(); ?>
                    <input type="hidden" name="currency_code" value="USD">
                    <input type="hidden" name="amount" value="<?php echo $net_payment; ?>">
                    <input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but03.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
                </form>
                
                <?php
            }
        }
    ?>
    this is the products.php page

    Code:
    <?php include('styles/top.php'); ?>
    
        <div id="full">
        
        <header>
        
            <h1>Yan Sum Kune - Shop</h1>
        
        </header>
        
        <?php include("cart.php"); ?>
        
        <div id="main_div">
            <h3> Shopping Cart</h3>
            <div id="division">
                <section id="main_section">
                    <?php display_cart(); ?>
                </section>
            
                <aside id="side">
                    <span class="your_cart">Your Cart</span>&nbsp;&nbsp;<br /><br />
                    <?php product(); ?>
                </aside>
                
            </div>
        
        </div>
        
        </div>
    
    <?php include('styles/bottom.php'); ?>
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width