Hi all,
I've got three types of users. When they log in i want them to go to a different page dependent on the type of user.
Its nearly workin but does anyone have any idea why the teacher check is workin but the student check isn't?
Also would using sessions be a better solution than using the include( ' ' ).
I've got three types of users. When they log in i want them to go to a different page dependent on the type of user.
Its nearly workin but does anyone have any idea why the teacher check is workin but the student check isn't?
Also would using sessions be a better solution than using the include( ' ' ).
Code:
<?php
$host="localhost"; // Host name
$username="student1"; // Mysql username
$password="student1"; // Mysql password
$db_name="wep"; // Database name
$tbl_name="user_tbl"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Define $myusername and $mypassword
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// check username and password
$sql="SELECT * FROM $tbl_name WHERE User_id='$myusername' and User_pass='$mypassword'";
$result=mysql_query($sql);
$rows = mysql_num_rows($result);
// if match found login
if($rows==1){
//check to see if student
$sql="SELECT * FROM user_tbl, student_tbl WHERE user_tbl.User_id='$myusername' AND student_tbl.User_id='$myusername'";
$result=mysql_query($sql);
$rows = mysql_num_rows($result);
//if == 1 user is a student
if($rows==1){
include( 'teacher.php' );
}
else{
//check to see if teacher
$sql="SELECT * FROM user_tbl, teacher_tbl WHERE user_tbl.User_id='$myusername' AND teacher_tbl.User_id='$myusername'";
$result=mysql_query($sql);
$rows = mysql_num_rows($result);
if($rows==1){
include( 'teacher.php' );
}
else{
//user is an employer
include( 'employer.php' );
}
}
}
//else check username
else{
$sql="SELECT * FROM $tbl_name WHERE User_id='$myusername'";
$result=mysql_query($sql);
$rows = mysql_num_rows($result);
// if == 1 username ok so password wrong
if($rows==1){
echo "Invalid password entered";
}
// wrong username
else{
echo "Invalid username entered";
}
}
?>
Comment