Page 1 of 1

Warning: cannot modify header information

Posted: Wed Apr 09, 2003 5:35 am
by jarow
I have a strange problem. When I execute this page on my local server (my machine) the redirect works just find. When I upload it to my remote server and try it I receive the following error message. Any idea why that is and what I can do about it??

Thanks


Warning: Cannot modify header information - headers already sent by (output started at /var/www/virtual/fauna/docs/www/Register/bd_register.php:6) in /var/www/virtual/fauna/docs/www/Register/bd_register.php on line 92

Code: Select all

<?php
include ('connlogin.php');?>
<html>
<head>
<title>Fauna Database Registration</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
li {
	color: #FFFFFF;
}
a:link {
color: #FFFFFF;
text-decoration: none;
font-weight: bold;
}
a:visited {
font-weight: bold;
color: #FFFFFF;
text-decoration: none;
}

a:hover {
color: #009999;
}

-->
</style>
</head>

<body>
<table width="600" align="center" cellpadding="1" cellspacing="1">
  <!--DWLayoutTable-->
  <tr bgcolor="003366">
    <td colspan="2" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
  </tr>
  <tr>
    <td width="213" valign="top" bgcolor="003366"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td width="374" valign="top" bgcolor="003366">

<?php 
require_once 'function3.php';

$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email_address = $_POST['email_address'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
$username = $_POST['username'];

$first_name = stripslashes($first_name);
$last_name = stripslashes($last_name);
$email_address = stripslashes($email_address);
$username = stripslashes($username);

// has the form been submitted?
if (isset($_POST['submit'])) {
    // the form has been submitted
    // perform data checks.
	$sql_email_check = mysql_query("SELECT email_address FROM users WHERE email_address='$email_address'");
	$sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'"); 
 	$email_check = mysql_num_rows($sql_email_check);
 	$username_check = mysql_num_rows($sql_username_check);
    $error_str = ''; // initialise $error_str as empty
    if (empty($_POST['first_name'])) $error_str .= '<li><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">You did not enter your first name</font></li>';
    if (empty($_POST['last_name'])) $error_str .= '<li><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">You did not enter your last name</font></li>';
    if (empty($_POST['email_address'])) $error_str .= '<li><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">You did not enter your E-mail address</font></li>';
    if (empty($_POST['username'])) $error_str .= '<li><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">You did not enter your desired username</font></li>';
    if (empty($_POST['password'])) $error_str .= '<li><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">You did not enter your desired password</font></li>';
    // more checks
    if ($_POST['password'] != $_POST['password2']) $error_str .= '<li><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Your passwords do not match.</font></li>';
    if (!preg_match("/.*@.*..*/", $_POST['email_address']) | preg_match("/(<|>)/", $_POST['email_address'])) $error_str .= '<li><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Invalid E-mail address</font></li>';
    if ($email_check > 0) $error_str .= '<li><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">E-mail address already in use, select another.</font></li>';
	if ($username_check > 0) $error_str .= '<li><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Username already in use, select another.</font></li>';
	// we could also strip any HTML from the variables, convert it to entities, have a maximum character limit on the values, etc etc, but this is just an example.
    // now, have any of these errors happened? We can find out by checking if $error_str is empty
    if (!empty($error_str)) {
        // errors have occured, halt execution and show form again.
        echo '<p><div align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">There were errors in the information you entered, they are listed below:</font></div></p>';
        echo '<ul>'.$error_str.'</ul>';
     	 // show form again
        user_form();
        } else { 
   $sql = "INSERT INTO USERS (first_name, last_name, email_address, username, password, signup_date) 
   VALUES('$first_name', '$last_name', '$email_address', '$username', '$password', NOW())"; 
   @mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>'); 

   if (mysql_affected_rows() < 1) { 
      echo 'There has been an error creating your account. Please contact the webmaster.'; 
      } 
	  else
	  { 
      header ("location: http://www.yahoo.com");
	  exit();
 	}
	}
} 

?>
</td>
  </tr>
  <tr bgcolor="#003366">
    <td colspan="2" valign="top"><table width="100%" cellpadding="1" cellspacing="1">
      <tr>
        <td width="17%" bgcolor="#003366"><div align="center"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif"><a href="#">El
                Proyecto</a></font></div>
        </td>
        <td width="19%" bgcolor="#003366"><div align="center"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Publicaciones</font></div>
        </td>
        <td width="23%" bgcolor="#003366"><div align="center"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Quienes
              Somos</font></div>
        </td>
        <td width="20%" bgcolor="#003366"><div align="center"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Fauna
              Ib&eacute;rica</font></div>
        </td>
        <td width="12%" bgcolor="#003366"><div align="center"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Enlaces</font></div>
        </td>
        <td width="9%" bgcolor="#003366"><div align="center"><font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Inicio</font></div>
        </td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>

?>

Posted: Wed Apr 09, 2003 5:55 am
by twigletmac
All of this HTML:

Code: Select all

<html> 
<head> 
<title>Fauna Database Registration</title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
<style type="text/css"> 
<!-- 
li &#123; 
   color: #FFFFFF; 
&#125; 
a:link &#123; 
color: #FFFFFF; 
text-decoration: none; 
font-weight: bold; 
&#125; 
a:visited &#123; 
font-weight: bold; 
color: #FFFFFF; 
text-decoration: none; 
&#125; 

a:hover &#123; 
color: #009999; 
&#125; 

--> 
</style> 
</head> 

<body> 
<table width="600" align="center" cellpadding="1" cellspacing="1"> 
  <!--DWLayoutTable--> 
  <tr bgcolor="003366"> 
    <td colspan="2" valign="top"><!--DWLayoutEmptyCell--> </td> 
  </tr> 
  <tr> 
    <td width="213" valign="top" bgcolor="003366"><!--DWLayoutEmptyCell--> </td> 
    <td width="374" valign="top" bgcolor="003366">
is output and you cannot have any output before using header().

Have a read of:
viewtopic.php?t=1157

Mac