hii all i want to login
but the problem is i enter the username and password it says failed.
im very sure the username and password is correct.anyone can explain why this happen?
but the problem is i enter the username and password it says failed.
im very sure the username and password is correct.anyone can explain why this happen?
<?phprequire_once 'database.php';
session_start();
function signIn()
{
$sql = 'SELECT username, user_type FROM users WHERE username = "'.addslashes($_POST['username']).'" ';
$sql .= 'AND password = "'.addslashes(md5($_POST['password'])).'";';
dbConnect();
$result = runQuery($sql);
if (mysql_num_rows($result) != 0)
{
$data = mysql_fetch_assoc($result);
$_SESSION['username'] = stripslashes($data['username']);
$_SESSION['user_type'] = $data['user_type'];
if ($_SESSION['user_type'] == 'student')
{
header('Location: studentpage.php');
}
else if ($_SESSION['user_type'] == 'staff')
{
header('Location: adminpage.php');
}
}
else {
header('Location: index2.php?status=SIGN-IN-FAILED');
}
}
function signOut()
{
session_destroy();
header('Location: index2.php');
}
function isSessionValid()
{
if (!isset($_SESSION['username']) || empty($_SESSION['username'])) {
signOut();
}
return true;
}
if ($_POST['action'] == 'login')
{
signIn();
}
if ($_GET['logout'] == 'true')
{
signOut();
}
?>