login check issue
Posted: Sat Oct 29, 2011 11:58 am
Hi, I am trying to perform a login check and redirect the form to index.php if the username and password are correct. Also the login page check if the fields are entered or not.
The issue is that the login check is performing but not redirecting to index.php. Also I'm not getting any error after performing the login check. Let me know if I'm making any errors in below code. Include file only contains the database details.
The issue is that the login check is performing but not redirecting to index.php. Also I'm not getting any error after performing the login check. Let me know if I'm making any errors in below code. Include file only contains the database details.
Code: Select all
<?php include("connections.php"); ?>
<?php
if(isset($_POST['submit']))
{
$errors=array();
$required_fields=array('username', 'pass');
foreach($required_fields as $fields)
{
if(!isset($_POST[$fields]) || empty($_POST[$fields]))
{
$errors[]=$fields;
}
}
if(empty($errors))
{
$username=trim($_POST['username']);
$password =trim($_POST['pass']);
$query= "SELECT * FROM users WHERE username='{$username}' AND hashed_password='{$password}' ";
$result=mysql_query($query);
$result_set=mysql_fetch_array($result);
if(mysql_num_rows($result_set) == 1)
{
header('location: index.php');
exit;
}
else
{
echo 'Invalid password';
}
}
}
?>