0

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....

2
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by danielbala
0

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.

0

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??

0

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.

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.