Warning: Cannot modify header information - headers already
Posted: Wed Sep 02, 2009 2:14 am
hi
i need help for this program........... i have created a table members with column names id, username, password.
in the database there is one record and after the user gives the username and password if the result matches the the page should redirect.
login.php
index.php
kindly help me on this issue,
i need help for this program........... i have created a table members with column names id, username, password.
in the database there is one record and after the user gives the username and password if the result matches the the page should redirect.
login.php
Code: Select all
<?php
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<center>
<form action="" method="post" name ="subform">
<table width="250" align="center" border="0" cellpadding="2" cellspacing="1">
<tr>
<td>
Username:  <input type="text" name="user" /><br>
</td>
</tr>
<tr>
<td>
Password:     <input type="password" name="pass" /><br>
</td>
</tr>
<tr>
<td>
                  <input type="submit" name="submit" value="Submit"/>
</td>
</tr>
</table>
</form>
</center>
<?php
$dblogin = "root";
$dbpwd = "";
$host = "localhost";
$dbconnection = mysql_connect($host,$dblogin,$dbpwd) or die ('error'.mysql_error());
$selectdb = mysql_select_db("example", $dbconnection);
if(!$selectdb)
{
echo "error in connection string".mysql_error();
}
else
{
echo "Connection Successfull";
}
echo "<br/>";
$username = $_POST['user'];
$password = $_POST['pass'];
$sql="SELECT * FROM members WHERE id='' and username='$username' and password='$password'";
$result = mysql_query($sql);
// This counts to see how many rows were found, there should be no more than 1
$count = mysql_num_rows($result);
if($count==1)
{
// Register $myusername, and redirect to file "login_success.php"
//session_start();
$_SESSION["logged"] = 1;
header("location:index.php");
}
else
{
$_SESSION["logged"] = 0;
header("location:login.php");
}
?>
</body>
</html>Code: Select all
<?php
//session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
echo "welcome".$_SESSION['username'];
?>
<a href="logout.php/">LogOut!</a>
</body>
</html>