4 Replies - 325 Views - Last Post: 09 May 2011 - 05:12 PM Rate Topic: -----

#1 dangmnx  Icon User is offline

  • D.I.C Regular

Reputation: -1
  • View blog
  • Posts: 428
  • Joined: 10-April 09

Warning ERROR I KEEP GETTING

Posted 09 May 2011 - 08:27 AM

I dont know why i keep getting this error;

Quote

Warning: Cannot modify header information - headers already sent by (output started at /hermes/web04/b2008/moo.battlesccom/validate.php:17) in /hermes/web04/b2008/moo.battlesccom/validate.php on line 35


<?php
session_start();
include("connect.php");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Battle Starcraft: SC1 NETWORK</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>

</head>
<body>
<div id="sample-container">
<div class="fbgreybox" style="width: 30%;"><?php include("login.php"); ?><?php include("kingtop.php"); ?></div><br/>
<div id="sample14">
<div id="header">
<a href="index.php">home</a>
</div>

<div id="gutter"></div>

<div id="col1">
<h2>Subhead</h2>

</div>

<div id="col2">
<h2>Subhead</h2>

<?php
session_start();

header('Location:http://www.starcraftz.net/');        //this makes it redirect straight back to the page specified
$user = $_POST['user'];
$pass = md5($_POST['pass']);

$db = mysql_connect('battlesccom.fatcowmysql.com', 'USERNAME', 'PW*');

if (!$db)
  {
  die('Could not connect: ' . mysql_error());
  }


$db_selected = mysql_select_db("battlesc", $db);

if (!db_selected)
{

die("cant connect");

}

$query30 = "Select ban FROM members WHERE setname = '".$user."'";
$result30 = mysql_query($query30) or die(mysql_error());

$name30 = mysql_fetch_array($result30);

$ban = $name30[ban];

if($ban == 0)
{

$query = "Select password FROM members WHERE setname = '".$user."'";
$result = mysql_query($query) or die(mysql_error());

$name = mysql_fetch_array($result);

$pass1 = $name[password];

if(strcmp($pass, $pass1) == 0 && strcmp($pass, '') != 0)
{
    $_SESSION['user'] = $user;     //creates the session variable $_SESSION['user']
    $_SESSION['pass'] = $pass;    //creates the session variable $_SESSION['pass']
    echo "Congratulations " .$user. " You are successfully <a href='index.php'>logged in.</a>";
   
}

else
{
    echo 'Username and/or Password do not match.';
}
}
else
{
    echo 'you are banned';
}
?>

</div>


<div id="col3">
<h2>Subhead</h2>
<p>test</p>
</div>

<div id="footer">Copyright  BATTLE SC 2011 - All rights reserved
Website designed and developed by Dang Mn.</div>
</div>


</div>

<div class="copyright">

</div>
</body>
</html>



Is This A Good Question/Topic? 0
  • +

Replies To: Warning ERROR I KEEP GETTING

#2 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 947
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: Warning ERROR I KEEP GETTING

Posted 09 May 2011 - 08:36 AM

You get error when you've already sent output to the browser before sending headers. To solve it either don't output anything to the browser (print, echo, HTML ....) or use output buffering to capture output.

Example
<?php
//beginning of script
ob_start();
?>
<html>
...
<!-- HTML, PHP and everything else here -->
...
</html>
<?php
//end of script
ob_end_flush(); //output everything to the browser now
?>


Was This Post Helpful? 1
  • +
  • -

#3 dangmnx  Icon User is offline

  • D.I.C Regular

Reputation: -1
  • View blog
  • Posts: 428
  • Joined: 10-April 09

Re: Warning ERROR I KEEP GETTING

Posted 09 May 2011 - 09:02 AM

Thank u! its gone, another error i'm getting is this...

How can i fix this error, it's not suppose to echo out that line...
Posted Image

Login.php
<?php
session_start();
if(isset($_SESSION['user']))     //This tells you if the user is logged in because $_SESSION['user'] exists
{

$db = mysql_connect('XXXX', 'XXXX', 'XXXX*');

if (!$db){
die('Could not connect: ' . mysql_error());
}

$db_selected = mysql_select_db("XXXXX", $db);
if (!db_selected){
die("cant connect");
}

$user2 = $_SESSION['user'];
$query = "Select * FROM members WHERE setname = '".$user2."'";

echo $query;
$result = mysql_query($query) or die(mysql_error());
$name2 = mysql_fetch_array($result);
$usercolor = $name2[setnamecolor];
$ban = $name2[ban];


echo 'You are logged in as: <u><font color="#535353">' .$usercolor;?></font></u>

<br/><br/>


<form action="logout.php" method="post">
<br>
<input type="submit" name="Logout" value="Logout" />
</form></font>


<?php
}
else
{
?>
<html>
<form action="validate.php" method="post">
<input type="text" name="user" size = "22" style = "font-size:14px;" value="Username"/>
<input type="password" name="pass" size = "22" style = "font-size:14px;" value="Password"/>
<input type="submit" name="Login" value="Login" /> </br><a href="register.php">Register?</a>
</form>
</html>

<?php } ?>

Was This Post Helpful? 0
  • +
  • -

#4 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 947
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: Warning ERROR I KEEP GETTING

Posted 09 May 2011 - 09:22 AM

You do have echo $query; on Line #20
Was This Post Helpful? 0
  • +
  • -

#5 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10596
  • View blog
  • Posts: 39,258
  • Joined: 27-December 08

Re: Warning ERROR I KEEP GETTING

Posted 09 May 2011 - 05:12 PM

For more reference, you can also check out this tutorial which goes into more detail on the headers already sent error. :)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1