I've been getting this error after I insert the require_once('login.php')

I've checked both files and I don't have any empty lines after the php closing tags as is usually the case with this error

This is the code

<html>
    <head>
        <title>Home</title>
    </head>
    <body>
    <link rel="stylesheet" type="text/css" href="style.css"/>
    <?php
    require_once('login.php');
    require_once('appvars.php');
    require_once('header.php');

    $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD,DB_NAME)
        or die('Error connecting to the MySQL server');

    $query = "SELECT * FROM products";

    $result = mysqli_query($dbc, $query)
        or die('Error querying database.');

    echo '<table BORDER = 1 Width=50% height=50% align="center">';

    while ($row = mysqli_fetch_array($result)) {
        $productname = $row['wineName'];
        $productdesc = $row['description'];
        $productprice = $row['price'];
        $imagefilename = $row['picturefilename'];
        $fullimagepath = UPLOAD_PATH.$imagefilename;

        echo '<tr>';
        echo '<td class= "productname">';
        echo  $productname;
        echo '</td>';

        echo '<td class = "productdesc">';
        echo $productdesc;
        echo '</td>';

        echo '<td class = "price">';
        echo $productprice;
        echo '</td>';

        echo '<td>';
        echo "<img src = '$fullimagepath' />";
        echo '</td>';

        echo '</tr>';
    }
    echo '</table>';
    require_once('Footer.php');
    ?>
</body>
</html>

And this is the warning I keep getting

Warning: Cannot modify header information - headers already sent by (output started at F:\PCH\xampp-win32-1.7.2\xampp\htdocs\Alfred\Index.php:7) in F:\PCH\xampp-win32-1.7.2\xampp\htdocs\Alfred\login.php on line 5

Can anyone help me with this please?

I've been getting this error after I insert the require_once('login.php')

I've checked both files and I don't have any empty lines after the php closing tags as is usually the case with this error

This is the code

<html>
    <head>
        <title>Home</title>
    </head>
    <body>
    <link rel="stylesheet" type="text/css" href="style.css"/>
    <?php
    require_once('login.php');
    require_once('appvars.php');
    require_once('header.php');

    $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD,DB_NAME)
        or die('Error connecting to the MySQL server');

    $query = "SELECT * FROM products";

    $result = mysqli_query($dbc, $query)
        or die('Error querying database.');

    echo '<table BORDER = 1 Width=50% height=50% align="center">';

    while ($row = mysqli_fetch_array($result)) {
        $productname = $row['wineName'];
        $productdesc = $row['description'];
        $productprice = $row['price'];
        $imagefilename = $row['picturefilename'];
        $fullimagepath = UPLOAD_PATH.$imagefilename;

        echo '<tr>';
        echo '<td class= "productname">';
        echo  $productname;
        echo '</td>';

        echo '<td class = "productdesc">';
        echo $productdesc;
        echo '</td>';

        echo '<td class = "price">';
        echo $productprice;
        echo '</td>';

        echo '<td>';
        echo "<img src = '$fullimagepath' />";
        echo '</td>';

        echo '</tr>';
    }
    echo '</table>';
    require_once('Footer.php');
    ?>
</body>
</html>

And this is the warning I keep getting

Can anyone help me with this please?

The header must come first in the response from a web server and is separated from the body by one blank line. The reason this error occurs is that some part of the body of the web page has been sent to the user already when a request is made to set a header value. Because PHP simplifies many things for you, the problem may be hiding in plain site. Here are some guidelines for finding the problem:

1) Find the header() statement that is causing the problem. The error must be at or before this line.

2) Look for any statements that could send output to the user before this header statement. If you find one or more, find some way to move the header statement before them. Complex conditional statements may complicate the issue, but they may also help solve the problem. Consider a conditional expression at the top of the PHP script that determines the header value as early as possible and sets it there.

3) Make sure there is no white space outside of the php start and end tags. While a blank line before the <?php start tag may look innocent, when processed by PHP, it will turn into an echo statement printing out a blank line. This is a common culprit.

This error comes when you print any thing before php hreader command

Example Error Code:
<?php
print “text”;
header(‘Location: http://www.example.com/’);
?>
<?php
	 require_once('login.php'); 
?>
		
		
<html>    
<head>        
<title>Home</title>    
</head>    
<body>    
<link rel="stylesheet" type="text/css" href="style.css"/>    
	
<?php    
	require_once('appvars.php');    
	require_once('header.php');     
	
	$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD,DB_NAME)        or die('Error connecting to the MySQL server');     
	$query = "SELECT * FROM products";     
	
	$result = mysqli_query($dbc, $query)        or die('Error querying database.');     
	echo '<table BORDER = 1 Width=50% height=50% align="center">';     
	while ($row = mysqli_fetch_array($result)) 
	{        
	$productname = $row['wineName'];        
	$productdesc = $row['description'];        
	$productprice = $row['price'];        
	$imagefilename = $row['picturefilename'];        
	$fullimagepath = UPLOAD_PATH.$imagefilename;         
	echo '<tr>';        
	echo '<td class= "productname">';        
	echo  $productname;        
	echo '</td>';         
	echo '<td class = "productdesc">';        
	echo $productdesc;        
	echo '</td>';         
	echo '<td class = "price">';        
	echo $productprice;        
	echo '</td>';         
	echo '<td>';        
	echo "<img src = '$fullimagepath' />";        
	echo '</td>';         
	echo '</tr>';    
	}    
	echo '</table>';    

	require_once('Footer.php');    
?>
</body>
</html>

Thanks a lot to both of you. I had been looking at this for an hour and now that it's been pointed out it's very obvious to see

Thanks a lot to both of you. I had been looking at this for an hour and now that it's been pointed out it's very obvious to see

mark a thread "solved" as soon as u get a solution

muranikalpana, thanks! a blank space was keeping the header redirection from working; it was driving me nuts.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.