0

Hi guyz i am getting an error on my header information..the warnig is displayed
when this part of code Runs

echo '<a href="' . 'ecomm_catalogue_view.php?product_code=' . $product_code .'" >'; '</a>';
            header("location: ecomm_catalogue_view.php?' . 'product_code=' . $product_code . '");

the warning displayed on top of each page is:

Warning: Cannot modify header information - headers already sent by (output started at \romajir\search.php:19) in C:\xampp\htdocs\romajir\search.php  on line 20

i dont know how to solve this any suggestion would help..thanx in advance
the search code for search.php is

<?php
include 'db.inc.php';
$db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD) or
die ('Unable to connect. Check your connection parameters.');
mysql_select_db(MYSQL_DB, $db) or die(mysql_error($db));

$search= (isset($_POST['search'])) ? trim($_POST['search']) : '';
if (isset($_POST['submit']) && $_POST['submit'] == 'Go') {
    if (empty($search)) {
    echo 'Their is Nothing to search!!';
    }
    else {
        $query = 'SELECT product_code FROM ecomm_products WHERE name = "' .
        $search . '"';
        $result = mysql_query($query, $db) or die(mysql_error());
        if (mysql_num_rows($result) > 0){
            $row = mysql_fetch_assoc($result);
            $product_code=$row['product_code'];
            echo '<a href="' . 'ecomm_catalogue_view.php?product_code=' . $product_code .'" >'; '</a>';
            header("location: ecomm_catalogue_view.php?' . 'product_code=' . $product_code . '");
            }
        else{
            echo 'We don\'t have that product. Sorry...';
            $search = '';
        }
    }
}
?>

Edited by mike_2000_17: Fixed formatting

3
Contributors
8
Replies
9
Views
7 Years
Discussion Span
Last Post by metalix
0

You can send header after soemthing is ECHOed. Place the header statements above all echo statements and also make sure that there arent any blank lines or spaces.

0

header statements can be placed after echo statements.
check there isn't even a space before first <?PHP
also try

include('db.inc.php');

brackets are important.

0

@shubhamjain, once i place it on top of the echo still it doesnt work..& where should i remove the space...i can't see any spaces within my code

0

@metalix i have done as u hve told me but now it doesnt move to the other page!!

0

header("location: ecomm_catalogue_view.php?' . 'product_code=' . $product_code . '");

you are mixing quotes
try

header("location: ecomm_catalogue_view.php?product_code=$product_code");
//or
header('location: ecomm_catalogue_view.php?product_code='.$product_code);

i think this is your problem

0

the general rule with quotes is that using "" doublequotes php will search through the string for things like $variable or $_SESSION or $var{$variable2}iable etc.
where as using ' ' single quotes they must be appended.
echo 'this is a '.$variable.' and a session'.$_SESSION;
you also need to close a text node you have opened.
like

'. . . product_code=' . $product_code . '");

after $product_code you opened another text node but closed with double quotes.
it is better to end without any quotes or $var.''
hope this helps :D

0

@metalix thanx i avoided using the code for ECHOing before the header and replaced tha header quotes with single quotes and it worked...thanx alot

cheerz!!!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.