-5

重複の可能性:
PHPによってすでに送信されているヘッダー

ローカルデータベースにphpmyadminを使用し、3つのphpページを使用して管理者パネルを操作し、ジョブリードを表示、編集、および削除できるようにしています。これがadminpanel.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">
<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>

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>

このエラーは、viewJobs.phpページの上部にエコーされます。

警告:ヘッダー情報を変更できません-143行目のC:\ xampp \ htdocs \ NokeeKweSite \ viewJobs.phpで(出力はC:\ xampp \ htdocs \ NokeeKweSite \ viewJobs.php:98で開始)によって既に送信されたヘッダー

4

2 に答える 2

0

すべてのコードを読んだわけではありませんが、次の方法で出力をバッファリングできます。

ob_start();
于 2012-06-14T18:40:53.080 に答える
0

あなたはできません

            setcookie("jobID", $jobID);

データが既にブラウザにプッシュされた後。

mysql_fetch ループ内で Cookie を設定しようとしています。

テーブルをエコーし​​ないでください。

<?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);
?>

そのビットをページの一番上に移動します。

後、

<div class="wideBox">

追加:

<?=$str;?>

これにより、Cookie を設定する前に情報がブラウザに送信されるのを防ぐことができます。

また、設定された Cookie は、MySQL ループ内では明るいアイデアではありません。複数の行を返す場合は、最後に返された行の値を設定するだけです。

于 2012-06-14T18:41:53.707 に答える