shotos
June 12th, 2008, 02:25 PM
Hi
i am trying to login to my database with a php script but i keep getting this error message.
Warning: Cannot modify header information - headers already sent by (output started at /home/kwasi/public_html/login.php:4) in /home/kwasi/public_html/login.php on line 22
below is the script........help will be appreciated
<html>
<body>
<?php
include("database.php");
$username = $_POST['username'];
$password = $_POST['password'];
if($username == ''){ unset($username); echo "No username submitted<br>";}
if($password == ''){ unset($password); echo "No password entered<br>";}
if (isset($username) && isset($password))
{
$ret = confirmUser($username, $password);
if(!$ret){
echo"Wrong username or password<br>";}
else{
/*session_register("username");
session_register("password");*/
header("location: login_success.php");}
} else
{
header("location: login.html");
}
function confirmUser($username, $password){
global $link;
$username = trim($username);
$password = trim($password);
$username = htmlspecialchars($username);
$password = htmlspecialchars($password);
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$query = "select * from users where username='$username' and password='$password'";
$result = mysql_query($query, $link);
$count = mysql_num_rows($result);
if($count==1){
return true;}
else{
return false; }
}
?>
</body>
</html>
i am trying to login to my database with a php script but i keep getting this error message.
Warning: Cannot modify header information - headers already sent by (output started at /home/kwasi/public_html/login.php:4) in /home/kwasi/public_html/login.php on line 22
below is the script........help will be appreciated
<html>
<body>
<?php
include("database.php");
$username = $_POST['username'];
$password = $_POST['password'];
if($username == ''){ unset($username); echo "No username submitted<br>";}
if($password == ''){ unset($password); echo "No password entered<br>";}
if (isset($username) && isset($password))
{
$ret = confirmUser($username, $password);
if(!$ret){
echo"Wrong username or password<br>";}
else{
/*session_register("username");
session_register("password");*/
header("location: login_success.php");}
} else
{
header("location: login.html");
}
function confirmUser($username, $password){
global $link;
$username = trim($username);
$password = trim($password);
$username = htmlspecialchars($username);
$password = htmlspecialchars($password);
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$query = "select * from users where username='$username' and password='$password'";
$result = mysql_query($query, $link);
$count = mysql_num_rows($result);
if($count==1){
return true;}
else{
return false; }
}
?>
</body>
</html>