hi...

im doing project for a school...and new to php and mysql..just learning..

i have to create one loginpage with 3 different users like corres,principal and the staff

in the table field what type i have to give like ENUM or SET..
i want to assign 0 for corr,1 for princi and 3 for staff..

how to do this and shud i give any field in the login page in php??

but im going to create only 2 tables one for corr and other one is for staff

correc table fields r corrs_id,username,password,staff_id,staff_role
staff table fields r staff_id,staff_role,name,qualification,address,state etc...

both the tables have 2 common fields staff_id and staff_role
now how to connect 2 tables and when username and password is given it shud first check the staff_role like princ or a staff

please help me....

Recommended Answers

All 5 Replies

Please someone help me in doing this project................

If you have a concrete question, a piece of code which doesn't work or a query which goes amiss, post it and we will try to help.

i created 2 tables
table1:
corr_id,usename,password,staff_id,staff_role
table:2
staff_id,staff_role,name address,phone,state,city,mobile,email.

now my question is how to assign 1 for corr,2 for prin and 3 for staff(in further many staff will be added..code in the php??

1. Don't use PHP to learn MySQL. Install the mysql command line client instead. Otherwise you will have a hard time to tell apart mysql and php mistakes and errors.
2. Im mysql you assign a value using the INSERT and UPDATE commands.
To insert key/value pairs in table1, use

INSERT INTO table1 (staff_id, staff_role) VALUES (0,'corr'),(1,'princi'),(3,'staff');

3. Don't use abbreviations. What is "corr", what is "princi", and who will know it when he has to revise your code in years to come?
4. staff_id and staff_role seem to be redundant in one table. If one staff_id point to exactly one staff_role, then staff_role should be eliminated from table1.
5. When you use the ENUM data type there is no need for numerical codes into the values. With ENUM types you can use the literal string constants 'corr', 'princi' etc. directly in your code without bothering with numerical codes for them.

this is my login.php

<?php
session_start();
include("config.php");
$UserName=$_POST;
$Password=$_POST;
$UserName = stripslashes($UserName);
$Password = stripslashes($Password);
$UserName= mysql_real_escape_string($UserName);
$Password = mysql_real_escape_string($Password);

$sql="SELECT * FROM admin WHERE username='$T_UserName' and password='$T_Password'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){

session_register("UserName");
session_register("Password");
header("location:correindex.php");
}
else {
echo "Wrong Username or Password";
}
}
?>

now if username and password is given it shud check the staff_role field in db whether they are 1 for corr,2 for prin and 3 for staff

i need the code and were to insert that code in login.php file

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.