tags:

views:

43

answers:

1

Hi, I would like to make a login page with 2 different user level, Admin & Staff. How can i do it using d code below.

Thank u.

    <?php

    $host="localhost";  
    $username="root";   
    $password="";  
    $db_name="profile";  
    $tbl_name="company";  


    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("Cannot Select Database");

    // username and password sent from form  
    $myusername=$_POST['myusername'];  
    $mypassword=$_POST['mypassword'];


    $myusername = stripslashes($myusername);  
    $mypassword = stripslashes($mypassword);  
    $myusername = mysql_real_escape_string($myusername);  
    $mypassword = mysql_real_escape_string($mypassword);   

    $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";  
    $result=mysql_query($sql);  

    // Mysql_num_row is counting table row  
    $count=mysql_num_rows($result);  

if($count==1){  

$_SESSION['myusername'] = $myusername;  
$_SESSION['mypassword'] = $mypassword; 
header("location:Admin_home.php");
}  
else {  
echo "Wrong Username or Password";  
}  
?> 

Login success :

session_start();   
if(!session_is_registered(myusername))
{     

header("location:Admin_home.php");    

}   
?>  
<html>
<body>
Login Successful  
</body>
</html>
A: 

Step 1: Create a file with a <form> in that directs to that script. Presumably you need 3 inputs (submit, username, password).

Step 2: Create a file that is named "login_success.php" so that it will redirect to it when it's done. Except you said you need two, one for admin one for normal.

Given your specifications of the project, that's all I can help you with. Try working with it a little bit, then show us what you have if you are still having problems.

If you know which user is admin:

$admin = "admin_username";
if($myusername == $admin) header("Location: admin_page.php");
else header("Location: normal_page.php");

but you have to know if the user is an admin or not. Either by hardcoding $admin or by adding a column to your sql that is is_admin or something.

Jason
I have the form. I juz like to know how to redirect two different user level to 2 different page. Example : if (user_level==1){header("location:admin_home.php");}else if{header("location:home.php");}
yash
Check my edit. You need to know the users level. Either by adding a column in the db or by hard coding as I did above.
Jason
i tot of creating a user level column. So if it admin = 1 and if staff = 2.. will dat be alrite?
yash
**PLEASE** format your code. In your original post you can highlight the code portion and press the button with '101010' on it. In comments, you can wrap your code in "`" (left of 1 on keyboard).
Jason
@yash - please try to use proper grammar and spelling. No offense, but people will take you more serious and be more willing to answer your question. I'm not even sure if I understand your question. Where would `admin = 1` and `staff = 1` be located?
Jason
ok Jason. Done it.
yash
@yash - thank you for formatting your code.
Jason
Sorry. I Would like to redirect the user (either admin or staff) to their respective pages. I'm considering creating a column in the db table named user level. So, if the user is admin = 1, and if staff = 2. So, `if (user_admin ==1) { header("location:admin_home.php"); } else if (user_staff ==2) { header("location:home.php"); }`
yash
That would work just fine.
Jason
No problem Jason, its my mistake anyway. :) Thankz
yash