Right now my login page is working fine. If both username and password are correct it returns a value of 1 and direct you to a page called studentloggedin.php In my database table i have a field called 'occupation' where there are two values: 'student' or 'lecturer'.
My problem is to create an if statement where if the user is a student it direct me to studentloggedin.php else it directs you to lecturerloggedin.php
I already tried to do a query but it isn't working.. please help :) MY code is here:
<?php
session_start();
//*********Server Information to establish a connection ******
$host = 'localhost';
$user = 'kurtfarrugia';
$password = '1234';
$database = 'kurt_farrugia';
$link = mysql_connect($host,$user,$password) or die('Error in Server information');
mysql_select_db($database,$link) or die('Can not Select Databasse');
//***************End Connection Establishment***************************************
//*******Form Information********
$userName = mysql_real_escape_string($_POST['username']); //User Name sent from Form
$password = mysql_real_escape_string($_POST['password']); // Password sent from Form
$rememberMe = strip_tags($_POST['rememberMe']);
setcookie("username", $_POST['username']);
//*********retrieving data from Database**********
$query = "select * from tbladmin where admin_usr_name='$userName' and
admin_pwd='$password'";
$res = mysql_query($query);
$rows = mysql_num_rows($res);
//**********it ensures that the script does not continue unless the username varaible is not null and not empty
if (!empty($_POST['username'])) {
$username = mysql_real_escape_string(strip_tags(trim($_POST['username'])));
} else {
//die('Hey turd, go back and fill in your username!');
header( "Location: login_fail2.php" ); die;
}
/*if ($rememberMe) {
setcookie("loggedIn", "yes", time()+3600);
header ("Location: studentloggedin.php" ); die;
}
else {
echo "Username and/or password is incorrect.";
}
if ($_COOKIE['loggedIn'] == "yes") {
header ("Location: studentloggedin.php" );
die();
}
*/
// HERE is the query
//$result2 = mysqli_query($con,"SELECT occupation FROM tbladmin WHERE admin_usr_name ='$username'" == 'student');
//$row == mysqli_fetch_array($result)
//**********if $userName and $password will match database, The above function will return 1 row
if($rows==1)
//{
{
//***if the userName and password matches then register a session and redrect user to the studentloggedin.php
//$_SESSION['userName'];
//$_SESSION['password'];
header("location:studentloggedin.php");
}
//}
else
{
header( "Location: login_fail2.php" ); die;
}
?>
header("location:studentloggedin.php");
toheader("Location: studentloggedin.php");
- got a feeling HTTP headers are fussy – verbumSapienti Apr 10 at 11:37