Link to home
Start Free TrialLog in
Avatar of wcws
wcws

asked on

Warning: Cannot add header information - headers already sent by (output started

Hello,

I am getting error when ever I try to login to the admin area the error is


Warning: Cannot add header information - headers already sent by (output started at /home/virtual/site14/fst/var/www/html/auction/admin/index.php:2) in /home/virtual/site14/fst/var/www/html/auction/admin/index.php on line 23


Please help me solving that error. following is my php script which causing that error :-


<? session_start(); ?>
<?php include("../lib/inc.php"); ?>
<?php

      session_register("userid");
      $msg = "";
      if (isset($action)) {
      if ($ausername == "") {      
            $msg = "Please enter username";
      } else {
      if ($apassword == "") {      
            $msg = "Please enter password";
      }
      }

      if (($ausername <> "") && ($apassword <> "")) {      

          $query = "SELECT admin_id from auc_admin where usernm='$ausername' and passwd='$apassword'" ;
          $rsl = mysql_query($query);  
          $row = mysql_fetch_array($rsl)  ;
                  if ($row[0] <> "") {      
                        $userid = $ausername;
                        header ("Location:adminhome.php");
                        exit;                        
                  } else {
                        $msg = "Incorrect username and password";
                  }
            }
            }
?>
<HTML>
<head>
<title>:: ADMIN AUCTION :: Admin Login</title>
<!--link rel="stylesheet" href="../../css/styles.css" type="text/css"-->
<script language="JavaScript">
var haverr = 0;
function validateForm(fld) {
    haverr = 0;

    if (fld.ausername.value.length < 1) {
       alert("Please enter username");
         fld.ausername.focus();
         return (false);
    }
    else {
    if (fld.apassword.value.length < 1) {
       alert("Please enter password");
         fld.apassword.focus();
         return (false);
    }
    else {
       return (true);
    }
    }

    return (false);
}

</script>
</head>
<BODY BGCOLOR="#FFFFFF" TEXT="#08428C" LINK="#08428C" VLINK="#08428C" ALINK="#08428C" LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0">
<BR><BR>
<TABLE BORDER=0 WIDTH=650 CELLPADDING=0 CELLSPACING=0 BGCOLOR="#FFFFFF" ALIGN="CENTER">
      <TR>
<TD>
      <CENTER>
                        <FONT FACE="Verdana, Arial, Helvetica, sans-serif" SIZE="4"><BR>
                        <BR>
                                                <FORM NAME=login method="post" onSubmit="return validateForm(this);" action="<?php echo $PHP_SELF ?>">
                              <TABLE WIDTH="400" BORDER="0" CELLSPACING="0" CELLPADDING="1" BGCOLOR="#336699">
                                    <TR>
                                          <TD>
                                                <TABLE WIDTH=100% CELLPADDING=3 ALIGN="CENTER" CELLSPACING="0" BORDER="0" BGCOLOR="#FFFFFF">
                                                      <TR BGCOLOR="#336699">
                                                            <TD COLSPAN="2" ALIGN=CENTER><FONT FACE="Tahoma, Verdana" SIZE="2" COLOR="#FFFFFF"><B>::
                                          Please log in for admin access ::</B></FONT></TD>
                                                      </TR>
                                                      <TR>
                                                            <TD></TD>
                                                            <TD> <FONT FACE="Verdana, Verdana, Arial, Helvetica, sans-serif" SIZE="2" COLOR=red><?php echo $msg; ?></FONT></TD>
                                                      </TR>
                                                      <TR>
                                                            <TD ALIGN=right> <FONT FACE="Verdana, Verdana, Arial, Helvetica, sans-serif" SIZE="2">
                                                                  Username                                                                  </FONT> </TD>
                                                            <TD>
                                                                  <INPUT NAME=ausername SIZE=20  VALUE="admin10">
                                                            </TD>
                                                      </TR>
                                                      <TR>
                                                            <TD ALIGN=right> <FONT FACE="Verdana, Verdana, Arial, Helvetica, sans-serif" SIZE="2">
                                                                  Password                                                                  </FONT> </TD>
                                                            <TD>
                                                                  <INPUT TYPE=password NAME=apassword SIZE=20  VALUE="adminpass">
                                                            </TD>
                                                      </TR>
                                                      <TR>
                                                            <TD></TD>
                                                            <TD>
                                                                  <INPUT TYPE=submit NAME=action VALUE="login">
                                                            </TD>
                                                      </TR>
                                                </TABLE>
                                          </TD>
                                    </TR>
                              </TABLE>
                        </FORM>
                                                </font>
                  </CENTER>
            </TD>
</TR>
</TABLE>
<p align="center"><font face="Tahoma" style="font-size: 8.5pt">©1997 - 2003 Wcws
Internet Inc. WS Auction.<br>
</font><br>
&nbsp;</p>
</BODY>
</HTML>

ASKER CERTIFIED SOLUTION
Avatar of Zontar
Zontar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Zontar
Zontar

      $query = "SELECT admin_id from auc_admin where usernm='$ausername' and passwd='$apassword'" ;

P.S. Tell me you're *not* storing passwords in the clear, please...
hey not only check for what zontar said also do one thing

put the html head part above the header function where ur redirecting the page.

<HTML>
<head>
...........
</head>

<?
....
header("...");
.....
?>

i guess this is the only problem ur getting

The header function must be used BEFORE any other HTML code

so header location must be on TOP of the page! !!

try to change order of scripting to get this thing to worK ...
Zontar's suggestion of not putting "ANYTHING" in front of the <?PHP worked perfectly for me!
-mxgrogg-