Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Warning - Headers already gone out?

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
I have a warning message:
Warning: Cannot modify header information - headers already sent by (output started at LG.php:10) in LG.php on line 45

Basically I have a problem with a log in sequence. If a user goes on the site, and does not enter any login data, but hits submit, he gets directed to Google. If the user then returns, but enters data and tries to log in pressing submit, then the warning above appears??

The initial form is an HTML form. The contents get posted to the form that checks if valid entry.

The code for the 1st form is:

<SELECT NAME=Location SIZE=7 style="font-weight: 700">
<OPTION>ITV Tyne Tees TV
<OPTION>ITV Westcountry TV
<OPTION>ITV Yorkshire TV
</SELECT></span></p>
<p><b><font face="Arial" size="4" color="#0000FF"><u>Please enter your name</u></font></b></p>
<p>
<font size="3" face="Arial">
<INPUT NAME="UserName" size="28" style="font-weight: 700" ></font></p>
<p><b><font face="Arial" size="4" color="#0000FF"><u>Please enter your </u></font></b>
<u><b><font face="Arial" size="4" color="#0000FF">user ID</font></b></u></p>
<p>
<font size="3" face="Arial">
<INPUT NAME="UserID" size="28" style="font-weight: 700" ></font></p>
<p><input type="submit" name="submit" value="Submit!"></p>
<p>&nbsp;</p>
<p>&nbsp;</p>

</form>
</body>
</html>


The data then gets posted to this PHP page/form

<?php
session_start();

$Location = $_POST['Location'] ;
$UserName = $_POST['UserName'] ;
$UID = $_POST['UserID'] ;


$db = mysql_connect("xxx", "xxx_xxx", "xxx");

mysql_select_db("xxx_xxx",$db) or die("Select DB Error: ".mysql_error());

$sql = "select * from Validnames where UserName = '$UserName' && UserID = '$UID' && Location = '$Location'";


if ($qry = mysql_query($sql)) {
$numrows = mysql_num_rows($qry);
}

if ($numrows > 0) {
// Dont forget to register the session if it isnt already
$_SESSION['UserName'] = $UserName;
header('location: newmenu.php');
exit();


} else {


// Send them on a jolly trip to google!
//header("Location: //exit();

$url = " echo '<script type="text/javascript">top.location.href = "' . $url . '";</script>';
}


?>

Any suggestions of where/why its going wrong appreciated.
 
this happens if you try to call the header after calling html code.

You have to put all the headers and session code before any html code as it has to parse that first.

Regards,

Martin

Computing Help And Info:
 
I just don't understand. All my other pages go in and out seamlessly beteen HTLL and PHP. The two problem pages here are 1st is All HTML, the 2nd all HTML tags removed. Could you show me where I am going wrong. Should my entry page be in php and not HTML. Many thanks
 
Problem is that php code you sent us is only 39 lines long and error mentions line 45, so there is a discrepancy there. This is not all the code you're using in LG.php. Could you post entire code for that file.

One of the problems why it is showing more lines than we can see is any whitespace before the initial <?php opening tag. That will count as output and will cause headers to be sent and result in an error.
 
Thanks Vragabond. Very strange, I just went in to try out the site and it doesn't go wrong?

The full code for the form LG.php is longer, as for pasting I removed a few lines I was using when I had problems getting a match in the database. Herewith:

<?php
session_start();



$Location = $_POST['Location'] ;
$UserName = $_POST['UserName'] ;
$UID = $_POST['UserID'] ;

//print ('Location is '. $Location . "<br>\n");
//print ('User is '. $UserName . "<br>\n");
//print ('UserID is '. $UID . "<br>\n");


$db = mysql_connect("xxx", "xxx", "xxx");

mysql_select_db("xxx",$db) or die("xxx".mysql_error());

//$sql = "select * from Validnames where Location = '$Location' && UserName = '$UserName' && UserID = '$UID'";

//$sql = "select * from Validnames where Location = '" . $Location . "'";

//$sql = "select * from Validnames where UserName = '" . $UserName . "'";

//$sql = "select * from Validnames where UserID = '" . $UID . "'";

//$sql = "select * from Validnames where UserName = '$UserName' && UserID = '$UID'";

$sql = "select * from Validnames where UserName = '$UserName' && UserID = '$UID' && Location = '$Location'";


if ($qry = mysql_query($sql)) {
$numrows = mysql_num_rows($qry);
}

if ($numrows > 0) {
// Dont forget to register the session if it isnt already
$_SESSION['UserName'] = $UserName;
header('location: newmenu.php');
exit();


} else {


// Send them on a jolly trip to google!
//header("Location: //exit();

$url = " echo '<script type="text/javascript">top.location.href = "' . $url . '";</script>';
}


?>

Regards
 
I have opening and closing the pages all night with no problems?, so thanks and just hope it stays this way.
If I had done a fix I would have said so, but it aint broke yet.

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top