-5

Possible Duplicate:
Headers already sent by PHP

I am using phpmyadmin for my local database, and 3 php pages to manipulate an administrator panel to be able to view, edit and delete job leads. here is the adminpanel.php page:

<!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"><!-- InstanceBegin template="/Templates/About.dwt" codeOutsideHTMLIsLocked="false" -->
    <head>
        <!-- InstanceBeginEditable name="doctitle" -->
            <title>.: Nokee Kwe - Admin Panel :.</title>
        <!-- InstanceEndEditable -->
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link rel="stylesheet" type="text/css" media="screen" href="layout.css" />
        <link rel="stylesheet" type="text/css" media="screen" href="style.css" />
         <script type="text/javascript">
//<![CDATA[
    if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1)
    document.write('<link rel=\"stylesheet\" type=\"text/css\" href=\"stylechr.css\" />');
    else if (navigator.userAgent.toLowerCase().indexOf('opera') > -1)
    document.write('<link rel=\"stylesheet\" type=\"text/css\" href=\"styleopr.css\" />');
    else
    document.write('<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />');
//]]>
    </script>
    <!--[if lte IE 8]>
    <link rel="stylesheet" type="text/css" href="ie.css" />
<![endif]-->
<!--[if IE 9]>
    <link rel="stylesheet" type="text/css" href="ie9.css" />
<![endif]--> 
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<style type="text/css">
form
{
    margin: 0 auto;
}
</style>
</head>
<body>
<div class="wrapper">
    <div class="header" id="ieHead">
                <div class="splashTop">
<!--[if lte IE 8]>
                    <img src="images/eagle.png" alt="eagle" />
                    <![endif]-->
<!--[if IE 9]>
                    <img src="images/eagle.png" alt="eagle" />
                    <![endif]-->
                        <div class="splashFAX" id="ieFax">Telephone: (519) 667-7088 • Facsimile: (519) 667-4872</div>
                        <div class="splashADDRESS" id="ieAddress">104-1069 Wellington Road South • London, Ontario • N6E 2H6</div>
                       <br/>
                       <span class="splashShare">
                        <span class="facebook"><script type="text/javascript">
//<![CDATA[
(function() {
    document.write('<fb:like href="www.facebook.com/NokeeKwe?sk=info" layout="button_count" show_faces="" width="50" action="like" font="tahoma" colorscheme="light"></fb:like>');
    var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
    s.type = 'text/javascript';
    s.async = true;
    s.src = 'http://connect.facebook.net/en_US/all.js#xfbml=1';
    s1.parentNode.insertBefore(s, s1);
})();
//]]>
</script>
                        </span><span class="twitter"><script type="text/javascript">
//<![CDATA[
(function() {
    document.write('<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-via="NokeeKwe">Tweet</a>');
    var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
    s.type = 'text/javascript';
    s.async = true;

    s.src = 'http://platform.twitter.com/widgets.js';
    s1.parentNode.insertBefore(s, s1);
})();
//]]>
</script></span>
                    </span>
                    </div>
                <div id="splashMain">
<object type="application/x-shockwave-flash" 
data="wheelNew.swf" 
width="400" height="350" style="float: right; position: absolute; margin: -10px 0 0 425px;" id="flashWheel">
<param name="movie" value="wheelNew.swf" />
<param name="quality" value="high"/>
<param name="wmode" value="transparent"/>
</object>
        <p class="title" id="em">About<br /> Nokee Kwe</p>
                                <p class="subtitle" id="emSub">Serving both Aboriginal<br/> and non-Aboriginal populations since 1978.</p>

                       </div>
                       <div id="navOuter">
                            <div id="nav">
                                <a href="about.html" target="_self"><span class="buttonNav" id="aboutBtn">About Us</span></a>
                                <a href="career.html" target="_self"><span class="buttonNav" id="cdBtn">Career Directions</span></a>
                                <a href="nlcentre.html" target="_self"><span class="buttonNav" id="nlcBtn">Native Education Centre</span></a>
                                <a href="index.html" target="_self"><span class="buttonNav" id="homeBtn">Home</span></a>
                            </div>
                       </div>
            </div>
<div class="wideBox">
<form action="AdminPanel.php" method="get">
    <p><button name="jobLead" value="addJob">+</button><button name="jobLead" value="viewJobs">&</button></p>
    </form>
    <?php
    if (isset($_GET['jobLead']))
    {
            switch($_GET['jobLead'])
            {
                case 'addJob':
                    echo "<META HTTP-EQUIV='Refresh' Content='0; URL=addJob.php'>";
                    break;
                case 'viewJobs':
                    echo "<META HTTP-EQUIV='Refresh' Content='0; URL=viewJobs.php'>";
                    break;
                default:

                    break;

            }
    }
    ?></div>
<div class="push"></div>
</div>
<div class="footer">
            <table width="900" border="0" cellspacing="0" cellpadding="0" class="footer-Links">
                <tr>
                    <td height="20" colspan="4">&nbsp;</td>
                </tr>
                <tr>
                    <td width="120" height="80" align="left" valign="middle" style="padding-left:40px;">
                        <a href="board.html">Board</a><br />
                        <a href="sponsors.html">Sponsors</a><br/>
                        <a href="funders.html">Funders</a><br/>
                        <a href="partners.html">Partners</a>
                    </td>
                    <td width="120" height="80" align="left" valign="middle">
                        <a href="history.html">History</a><br />
                        <a href="vision.html">Vision</a><br />
                        <a href="mission.html">Mission</a>
                    </td>
                    <td width="200" height="80" align="left" valign="middle">
                    <a href="contact.html">Contact Nokee Kwe</a><br/>
                        <a href="career.html">Career Directions</a><br />
                        <a href="nlcentre.html">Native Education Centre</a>
                    </td>
                    <td height="100">
                        <a href="index.html"><img src="images/bottom/nokeekwe_logo.png" alt="" width="350" height="80" border="0"/></a>
                    </td>
                </tr>
            </table>
        </div>
                <!-- Website Tracking Scripts -->
                <script type="text/javascript">
                    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
                    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
                </script>
                <script src="A%20CSS%20Sticky%20Footer_files/ga.js" type="text/javascript"></script>
                <script type="text/javascript">
                    var pageTracker = _gat._getTracker("UA-271290-1");
                    pageTracker._initData();
                    pageTracker._trackPageview();
                </script>

</body>
</html>

When you go to viewJobs.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"><!-- InstanceBegin template="/Templates/About.dwt" codeOutsideHTMLIsLocked="false" -->
    <head>
        <!-- InstanceBeginEditable name="doctitle" -->
            <title>.: Nokee Kwe - Admin Panel :.</title>
        <!-- InstanceEndEditable -->
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link rel="stylesheet" type="text/css" media="screen" href="layout.css" />
        <link rel="stylesheet" type="text/css" media="screen" href="style.css" />
         <script type="text/javascript">
//<![CDATA[
    if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1)
    document.write('<link rel=\"stylesheet\" type=\"text/css\" href=\"stylechr.css\" />');
    else if (navigator.userAgent.toLowerCase().indexOf('opera') > -1)
    document.write('<link rel=\"stylesheet\" type=\"text/css\" href=\"styleopr.css\" />');
    else
    document.write('<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />');
//]]>
    </script>
    <!--[if lte IE 8]>
    <link rel="stylesheet" type="text/css" href="ie.css" />
<![endif]-->
<!--[if IE 9]>
    <link rel="stylesheet" type="text/css" href="ie9.css" />
<![endif]--> 
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<style type="text/css">
form
{
    margin: 0 auto;
}
</style>
</head>
<body>
<div class="wrapper">
    <div class="header" id="ieHead">
                <div class="splashTop">
<!--[if lte IE 8]>
                    <img src="images/eagle.png" alt="eagle" />
                    <![endif]-->
<!--[if IE 9]>
                    <img src="images/eagle.png" alt="eagle" />
                    <![endif]-->
                        <div class="splashFAX" id="ieFax">Telephone: (519) 667-7088 • Facsimile: (519) 667-4872</div>
                        <div class="splashADDRESS" id="ieAddress">104-1069 Wellington Road South • London, Ontario • N6E 2H6</div>
                       <br/>
                       <span class="splashShare">
                        <span class="facebook"><script type="text/javascript">
//<![CDATA[
(function() {
    document.write('<fb:like href="www.facebook.com/NokeeKwe?sk=info" layout="button_count" show_faces="" width="50" action="like" font="tahoma" colorscheme="light"></fb:like>');
    var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
    s.type = 'text/javascript';
    s.async = true;
    s.src = 'http://connect.facebook.net/en_US/all.js#xfbml=1';
    s1.parentNode.insertBefore(s, s1);
})();
//]]>
</script>
                        </span><span class="twitter"><script type="text/javascript">
//<![CDATA[
(function() {
    document.write('<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-via="NokeeKwe">Tweet</a>');
    var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
    s.type = 'text/javascript';
    s.async = true;

    s.src = 'http://platform.twitter.com/widgets.js';
    s1.parentNode.insertBefore(s, s1);
})();
//]]>
</script></span>
                    </span>
                    </div>
                <div id="splashMain">
<object type="application/x-shockwave-flash" 
data="wheelNew.swf" 
width="400" height="350" style="float: right; position: absolute; margin: -10px 0 0 425px;" id="flashWheel">
<param name="movie" value="wheelNew.swf" />
<param name="quality" value="high"/>
<param name="wmode" value="transparent"/>
</object>
        <p class="title" id="em">About<br /> Nokee Kwe</p>
                                <p class="subtitle" id="emSub">Serving both Aboriginal<br/> and non-Aboriginal populations since 1978.</p>

                       </div>
                       <div id="navOuter">
                            <div id="nav">
                                <a href="about.html" target="_self"><span class="buttonNav" id="aboutBtn">About Us</span></a>
                                <a href="career.html" target="_self"><span class="buttonNav" id="cdBtn">Career Directions</span></a>
                                <a href="nlcentre.html" target="_self"><span class="buttonNav" id="nlcBtn">Native Education Centre</span></a>
                                <a href="index.html" target="_self"><span class="buttonNav" id="homeBtn">Home</span></a>
                            </div>
                       </div>
            </div>
<div class="wideBox">
<?php
        $jobID = 0;
        $rows = 0;
        $errors = 0;
        $DBConnect = @mysql_connect("localhost", "root");

        if($DBConnect === FALSE)
        {
            echo "<p>Unable to connect to the database server. " .
            "Error code " . mysql_errno() . ": " .
            mysql_error() . "</p>\n";
            $errors++;
        }
        else
        {
            $DBName = "nokeekwe";
            $result = @mysql_select_db($DBName, $DBConnect);

            if($result === FALSE)
            {
                echo "<p>Unable to select the database. " .
                "Error code " . mysql_errno($DBConnect) . ": " .
                mysql_error($DBConnect) . "</p>\n";
                $errors++;
            }
        }
        if($DBConnect !== FALSE)
        {
            $jobID = 0;
            $errors = 0;
            $title = "";
            $desc = "";
            $req = "";
            $employer = "";
            $phone = "";
            $fax = "";
            $email = "";
            $address = "";
            $TableName = "tbljobs";
            $SQLstring = "SELECT * FROM tbljobs";
            $QueryResult = @mysql_query($SQLstring, $DBConnect);

            while(($Row = mysql_fetch_row($QueryResult)) !== FALSE)
            {
                $jobID = $Row[0];
                setcookie("jobID", $jobID);
                echo "<table>\n";
                echo "<tr><td>Job ID #: $Row[0]</td></tr>\n";
                echo "<tr><td>Job Title: $Row[1]</td></tr>\n";
                echo "<tr><td>Job Description: $Row[2]</td></tr>\n";
                echo "<tr><td>Job Requirements: $Row[3]</td></tr>\n";
                echo "<tr><td>Employer: $Row[4]</td></tr>\n";
                echo "<tr><td>Phone: <br /> $Row[5]</td></tr>\n";
                echo "<tr><td>Fax: <br /> $Row[6]</td></tr>\n";
                echo "<tr><td>Email: <br /> $Row[7]</td></tr>\n";
                echo "<tr><td>Address: <br /> $Row[8]</td></tr>\n";
                echo "<form action='editJobs.php' method='request'><button name='func' value='edit'>Edit</button><button name='func' value='delete'>Delete</button></form></tr>\n";
                echo "</table>\n";;

            }   
        }
        $rows =  mysql_num_rows($QueryResult);
        if($rows == 0)
        {
            echo "no jobs to show\n";
        }
        mysql_close($DBConnect);
?>
</div>
<div class="push"></div>
</div>
<div class="footer">
            <table width="900" border="0" cellspacing="0" cellpadding="0" class="footer-Links">
                <tr>
                    <td height="20" colspan="4">&nbsp;</td>
                </tr>
                <tr>
                    <td width="120" height="80" align="left" valign="middle" style="padding-left:40px;">
                        <a href="board.html">Board</a><br />
                        <a href="sponsors.html">Sponsors</a><br/>
                        <a href="funders.html">Funders</a><br/>
                        <a href="partners.html">Partners</a>
                    </td>
                    <td width="120" height="80" align="left" valign="middle">
                        <a href="history.html">History</a><br />
                        <a href="vision.html">Vision</a><br />
                        <a href="mission.html">Mission</a>
                    </td>
                    <td width="200" height="80" align="left" valign="middle">
                    <a href="contact.html">Contact Nokee Kwe</a><br/>
                        <a href="career.html">Career Directions</a><br />
                        <a href="nlcentre.html">Native Education Centre</a>
                    </td>
                    <td height="100">
                        <a href="index.html"><img src="images/bottom/nokeekwe_logo.png" alt="" width="350" height="80" border="0"/></a>
                    </td>
                </tr>
            </table>
        </div>
                <!-- Website Tracking Scripts -->
                <script type="text/javascript">
                    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
                    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
                </script>
                <script src="A%20CSS%20Sticky%20Footer_files/ga.js" type="text/javascript"></script>
                <script type="text/javascript">
                    var pageTracker = _gat._getTracker("UA-271290-1");
                    pageTracker._initData();
                    pageTracker._trackPageview();
                </script>

</body>
</html>

you get this error echoed at the top of the viewJobs.php page:

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\NokeeKweSite\viewJobs.php:98) in C:\xampp\htdocs\NokeeKweSite\viewJobs.php on line 143

Community
  • 1
  • 1
Ksenia
  • 3
  • 1
  • 3
    Also, when you ask a question, post only relevant information. Nobody is going to go through hundreds of lines of code when the error is on one specific line. Definitely include that part of the code (and anything else we need to understand it), but the rest is unnecessary. – sachleen Jun 14 '12 at 18:36
  • user1366254, nobody is obligated to help you in any way. Nobody gets paid here. If you're unwilling to make it as easy as you can to get an accurate response, why should anyone be willing to take the time to go through hundreds of lines of your code? – Mike Jun 14 '12 at 19:05
  • @user1366254 No, you need to help us help you. Besides, the links I posted should explain why you're getting this error. Consider reading them. – sachleen Jun 14 '12 at 19:08

2 Answers2

0

I didn't read all your code, but you could buffer your output with:

ob_start();
HBv6
  • 3,487
  • 4
  • 30
  • 43
0

You cannot do

            setcookie("jobID", $jobID);

After data has already been pushed to the browser.

You are trying to set a cookie within your mysql_fetch loop.

Don't echo the table, but do..

<?php
    $jobID = 0;
    $rows = 0;
    $errors = 0;
    $DBConnect = @mysql_connect("localhost", "root");

    if($DBConnect === FALSE)
    {
        $str = "<p>Unable to connect to the database server. " .
        "Error code " . mysql_errno() . ": " .
        mysql_error() . "</p>\n";
        $errors++;
    }
    else
    {
        $DBName = "nokeekwe";
        $result = @mysql_select_db($DBName, $DBConnect);

        if($result === FALSE)
        {
            $str = "<p>Unable to select the database. " .
            "Error code " . mysql_errno($DBConnect) . ": " .
            mysql_error($DBConnect) . "</p>\n";
            $errors++;
        }
    }
    if($DBConnect !== FALSE)
    {
        $jobID = 0;
        $errors = 0;
        $title = "";
        $desc = "";
        $req = "";
        $employer = "";
        $phone = "";
        $fax = "";
        $email = "";
        $address = "";
        $TableName = "tbljobs";
        $SQLstring = "SELECT * FROM tbljobs";
        $QueryResult = @mysql_query($SQLstring, $DBConnect);

        while(($Row = mysql_fetch_row($QueryResult)) !== FALSE)
        {
            $jobID = $Row[0];
            setcookie("jobID", $jobID);
            $str .= "<table>\n";
            $str .= "<tr><td>Job ID #: $Row[0]</td></tr>\n";
            $str .= "<tr><td>Job Title: $Row[1]</td></tr>\n";
            $str .= "<tr><td>Job Description: $Row[2]</td></tr>\n";
            $str .= "<tr><td>Job Requirements: $Row[3]</td></tr>\n";
            $str .="<tr><td>Employer: $Row[4]</td></tr>\n";
            $str .="<tr><td>Phone: <br /> $Row[5]</td></tr>\n";
            $str .="<tr><td>Fax: <br /> $Row[6]</td></tr>\n";
            $str .="<tr><td>Email: <br /> $Row[7]</td></tr>\n";
            $str .="<tr><td>Address: <br /> $Row[8]</td></tr>\n";
            $str .="<form action='editJobs.php' method='request'><button name='func' value='edit'>Edit</button><button name='func' value='delete'>Delete</button></form></tr>\n";
            $str .="</table>\n";;

        }   
    }
    $rows =  mysql_num_rows($QueryResult);
    if($rows == 0)
    {
        $str .="no jobs to show\n";
    }
    mysql_close($DBConnect);
?>

Move that bit to the very top of your page.

After,

<div class="wideBox">

Add:

<?=$str;?>

This will prevent information being sent to the browser before you set the cookie.

Also, your set cookie is not a bright idea inside of the MySQL loop. If you return multiple rows, all you are doing is setting it to the value of the last row returned.

Mike Mackintosh
  • 13,917
  • 6
  • 60
  • 87