Hi,
I am working on login form.When i redirect a page its showing an error given below.
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\job\login.php:49) in C:\xampp\htdocs\job\login.php on line 50
need help.
Thanks
<?php
//Start session
session_start();
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="ihmjob"; // Database name
$tbl_name="login"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
mysql_select_db("$db_name")or die("cannot select DB");
//Array to store validation errors
$errmsg_arr = array();
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
if(isset($_POST['submit']))
{
//Sanitize the POST values
$login = clean($_POST['uemail']);
$password = clean($_POST['pass']);
//Input Validations
if($login == '') {
$errmsg_arr[] = 'Login ID missing';
$errflag = true;
}
if($password == '') {
$errmsg_arr[] = 'Password missing';
$errflag = true;
}
//If there are input validations, redirect back to the login form
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
echo "Wrong username & password";
header("location: login.php");
exit();
}
//Create query
$qry="SELECT * FROM login WHERE uemail='$login' AND pass='$password'";
echo "SELECT * FROM login WHERE uemail='$login' AND pass='$password'";
$result=mysql_query($qry);
//Check whether the query was successful or not
if($result) {
if(mysql_num_rows($result) == 1)
{
echo "Login Successful";
/*session_regenerate_id();
$member = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $member['member_id'];
$_SESSION['SESS_FIRST_NAME'] = $member['firstname'];
$_SESSION['SESS_LAST_NAME'] = $member['lastname'];
session_write_close();
header("location: member-index.php");
exit();
}*/
header("location: admin.php");
exit();
}
else {
echo "Login failed";
header("location: login-failed.php");
exit();
}
}
}
?>