header redirect

I have the following script:
function draw_det_content($id)

{

db_connect();

$id=de_code_url($id);

$html="";

$main=str_replace("'","''",$main);

$sub=str_replace("'","''",$sub);

$r=mysql_query("SELECT * FROM products WHERE product_id ='$id'");

if(mysql_affected_rows())

{

	$row=mysql_fetch_array($r);

	$name=$row["name"];
	
	$price=$row["price"];
	
	$brand=$row["brand"];

	$image=$row["image"];

	$description=$row["description"];
	
	$pid=$row["product_id"];

	$link=$row["url"];

	if(strcmp("",$image))

	$html.=""; //content here;

	db_close();

	print $html;

}

else

header( “Location: 404.shtml” );

}

When the product is not available the 404.shtml page should show.
But I get the following error message:
Warning: Cannot modify header information - headers already sent by (output started at /home/densclot/public_html/jackets/index.php:171) in /home/densclot/public_html/jackets/functions.php on line 1167

The relevant section in the index.php file is:
if(isset($p))

{

db_connect();

$r=mysql_query(“SELECT * FROM products WHERE product_id=’”.de_code_url($p)."’");

$row=mysql_fetch_array($r);



$page_title=$row["name"];

$msg=substr($row["description"],0,150);

$meta_desc="$msg..";

$meta_keywords="$page_title,";

		$link=code_url($row["product_id"]);

$canonical="$base_url/p/$link/";


db_close();

}

I need help to modify the script to return the 404 header.
Thank you.

Add the entire index file, and please use the php-button in the toolbar here to create a php code field.

The index.php file is below:

[php]<?php

include(“functions.php”);

$page_title="";

$meta_desc="";
$meta_keywords=" ";

if(strcmp($c,""))

{

$c=de_code_url($c);



$c_arr=explode("_SUB_",$c);



$main=$c_arr[0];



$sub=$c_arr[1];



$sub2=$c_arr[2];



if(strcmp($sub2,""))



{



	$page_title="$sub2, $sub, $main";





}



elseif(strcmp($sub,""))



{



	$page_title="$sub, $main";






}



else



{



	$page_title="$main";






}

}

if(isset($p))

{

db_connect();

$r=mysql_query(“SELECT * FROM products WHERE product_id=’”.de_code_url($p)."’");

$row=mysql_fetch_array($r);



$page_title=$row["name"];

$msg=substr($row["description"],0,150);

$meta_desc="$msg..";

$meta_keywords="$page_title,";

		$link=code_url($row["product_id"]);

$canonical="$base_url/p/$link/";


db_close();

}

?>

<?php print $page_title; ?> "> [/php]

Thank you

Sorry, by mistake I did not include the entire index.php file. Here it is:

[php]

<?php include("functions.php"); $page_title=""; $meta_desc=""; $meta_keywords=" "; if(strcmp($c,"")) { $c=de_code_url($c); $c_arr=explode("_SUB_",$c); $main=$c_arr[0]; $sub=$c_arr[1]; $sub2=$c_arr[2]; if(strcmp($sub2,"")) { $page_title="$sub2, $sub, $main"; } elseif(strcmp($sub,"")) { $page_title="$sub, $main"; } else { $page_title="$main"; } } if(isset($p)) { db_connect(); $r=mysql_query("SELECT * FROM products WHERE product_id='".de_code_url($p)."'"); $row=mysql_fetch_array($r); $page_title=$row["name"]; $msg=substr($row["description"],0,150); $meta_desc="$msg.."; $meta_keywords="$page_title,"; $link=code_url($row["product_id"]); $canonical="$base_url/p/$link/"; db_close(); } ?> <?php print $page_title; ?> ">
    	<div id="MainPageHolder"><!-- MainPageHolder Start -->
        	<div id="Header"></div>
            <div id="MainContentHolder"><!-- MainContentHolder Start -->
            	<div id="LeftHolder">

 

    <?php draw_nav($main,$start); ?>

 

                </div>
				
                <div id="RightHolder"><!-- RightHolder Start -->
<?php if(strcmp($c,"")) draw_content($c,$start); elseif(isset($p)) draw_det_content($p); else include("index_content.php"); ?>
            </div><!-- MainContentHolder End -->

            <div id="MainFooterHolder">
            </div><!-- MainFooterHolder End -->
        </div><!-- MainPageHolder End -->
    </div><!-- PageHolder End -->
</div><!-- PageWrapper End -->

[/php]

Thank you.

You are running the function after outputting data to the browser. All header modifications like redirect/cookies must be sent before any html.

What you could do is make a function to only check if the product exists, and if not, redirect. Then run that function before all the code.

Thank you for the info. I am not a php programmer.
Can I get paid help to do this job?

Sure, there are a lot of freelance/programmer for hire websites out there,

Sponsor our Newsletter | Privacy Policy | Terms of Service