This question already has an answer here:
I am still getting that error when I run my code. Here is my code.I removed all white spaces as well.my form on my html goes to my php (action="lib/login.php") file to check if user exists. If it exist, then redirect. dbconnect.php just connects to my database. can anyone help?
FOLDER Layout:
lib
-dbconnect.php
-login.php (code located below)
index.html
<?php
require_once("dbconnect.php");
$loginuser = $_POST['username'];
$loginpw = $_POST['password'];
$usertable = "Users";
$users="Username";
$pw="Password";
$query = "SELECT $users, $pw FROM $usertable WHERE $users='$loginuser' AND $pw='$loginpw'";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
if ($num_rows>0) {
header("Location:../index.html");
exit();
}
?>
</div>
This message appears if you try to send a HTTP header after you already made some output. This is because in HTTP there comes first the headers and then the body. As ouput goes to the body, it is impossible to send headers anymore after output.
As there is no echo
, print
or whatever output function used in your code, output can be generated by
<?php
To 1:
The ob_*
set of functions is a good way to catch all output a script regardless if this are error messages or regular output. So you could add the line:
ob_start();
direct after the opening <?php
tag.
Then before the call to header()
add:
if(ob_get_size() > 0) {
// there was an error, display it and exit
ob_end_flush();
die();
}
Note that in production environment you should disable the display of error messages at all as they can contain sensitive information. You can do by settings display_errors in php.ini to 0 or per script by:
ini_set('display_errors', 0);
To 2:
Assuming that the code you have posted is the complete content of the php file (no spaces or empty lines before <?php
) it could be that you have a problem with the UTF-8 BOM char. BOM means byte order mark and is used internally by the utf-8 encoding. And it is not visible in a text editor. :)
To remove it, there are several solutions out there.. will google one for you ..... http://www.w3.org/International/questions/qa-byte-order-mark.en.php