Jump to content

[SOLVED] Header issue


log2

Recommended Posts

Ok, so I know someone's first response will be read the sticky, lol, but I already did, didn't help.

 

I'll give you a little background as I write this post as I am new to the forums. I am Log2. I've been coding php for about 6 years now, and building web sites for about 9. Now usually I can solve these problems on my own, but this one I can't seem to get it.

 

Anywho, here's the issue, I am getting a header issue when creating my shopping cart, here's the message exactly:

Warning: Cannot modify header information - headers already sent by (output started at /home/bell2142/public_html/temp/index.php:9) in /home/bell2142/public_html/temp/process.php on line 296

Now line 9 in index.php is the starting of my javascript info (which isn't much)

 

<?
require_once ("process.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>title - edited out</title>
<script type="text/javascript">

 

There's index.php (well the beginning)

Now the file that I'm calling that from, line 296 is a setcookie. When I comment out the set cookie, works perfectly (except obviously not setting a cookie, lol)

public function find_user() {
	$this->user_name = session_id();
	if (isset($_COOKIE['username'])) {
		$this->user_name = $_COOKIE['username'];
	}

	$result = mysql_query("SELECT * FROM " . $this->user_name);
	if ($result) {
		if (!isset($_COOKIE['username'])) {
			setcookie('username', $this->user_name, time()+3600);
		}
		else {

		}
		return;
	}
	else {

	}
}

 

297 is the only setcookie in there, and here's the function (placed after that function) calling that function:

function showCart() {
	$this->connect_to_db();
	$this->find_user();
	$que = mysql_query("SELECT * FROM " . $this->user_name);
	$info = array("sku" => array(), "name" => array(), "quantity" => array(), "price" => array(), "size" => array());
	$i = 0;
	while ($row = mysql_fetch_array($que)) {
		$info["sku"][$i] = $row["itemName"];
		$info["quantity"][$i] = $row["quantity"];
		$info['size'][$i] = $row['size'];
		$query = mysql_fetch_array(mysql_query("SELECT * FROM itemList WHERE sku=" . $info["sku"][$i]));
		$info["name"][$i] = $query["name"];
		$info['price'][$i] = $query['price'];
		$i++;
	}
	return $info;
}

 

Now I really don't want to post my whole file, but as far as I can see I'm NOT sending any information anywhere before that, I am calling $cart->showCart() from another file, and it just parses the array to be legible. Anyway, any help is greatly appreciated as I have been working on this for about 4 hours, and it's becoming tiring, however I will take a rest (as that usually helps most programmers) then continue working on it, as I anxiously await a reply

 

Thanks for reading

Link to comment
https://forums.phpfreaks.com/topic/180534-solved-header-issue/
Share on other sites

pretty much the only way I know how to do it, as I am pretty sure there is no other way to link a php file to an html file

 

Yeah, Ive no idea what you mean.

 

Anyway, its pretty hard to tell your logic from here but I'll tell you this. The error you are getting means there IS output being sent somewhere. Without posting all your code you'll likely need to track it down yourself.

 

Have you checked for whitespace?

 

The code inside your functions won't actually be evaluated until it is called, sure your not calling this showcart() function (and therefore find_user() and setcookie()) after output?

Link to comment
https://forums.phpfreaks.com/topic/180534-solved-header-issue/#findComment-952445
Share on other sites

pretty much the only way I know how to do it, as I am pretty sure there is no other way to link a php file to an html file

 

Yeah, Ive no idea what you mean.

 

What I mean here is that I don't know of another way to call a function from a PHP file without linking (or including or requiring) it inside an HTML file. Needs to be called

 

 

Also I fixed it with your guidlines Thorpe. Obviously no whitespace, not a rookie :P lol

However I was calling the showCart() after output, that's how I thought I've always done it, but I guess it was some other way.. obviously, lol, it's fixed, thanks a lot

Link to comment
https://forums.phpfreaks.com/topic/180534-solved-header-issue/#findComment-952449
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.