会话和包含功能给出:
session_start();
include("config.php");
if(isset($_POST['T_UserName']) && isset($_POST['T_Password']) && !empty($_POST['T_UserName']) && !empty($_POST['T_Password']))
{
从表单发送的用户名和密码:
$T_UserName=$_POST['T_UserName'];
$T_Password=$_POST['T_Password'];
保护MySQL注入:
$T_UserName = stripslashes($T_UserName);
$T_Password = stripslashes($T_Password);
$T_UserName= mysql_real_escape_string($T_UserName);
$T_Password = mysql_real_escape_string($T_Password);
$sql="SELECT * FROM login WHERE username='$T_UserName' and password='$T_Password'"; $result=mysql_query($sql);
Mysql_num_row正在计算表行:
$count=mysql_num_rows($result);
如果结果与$ T_UserName和$ T_Password匹配,则表行必须为1行:
if($count==1)
{
注册$ T_UserName,$ T_Password并重定向到文件“correspindex.php”:
session_register("T_UserName");
session_register("T_Password");
重定向到错误页面或显示错误消息然后:
if(isset($_POST['emp_role'])
{
$userinfo = mysql_fetch_assoc($sql);
$emp_role = $userinfo['emp_role'];
if($emp_role == 1)
{
header("location:corrrespondindex.php");
}
elseif($emp_role == 2 )
{
header("location:principalindex.php");
}
elseif($emp_role == 3)
{
header("location:staffindex.php");
}
closes out if the user DOES exist:
header("location:loginhome.php");
}
else
{
echo "Wrong Username or Password";
}
}
}
php is closed
this is the php code im getting so many error
i create 1table with id,username,password and role(ENUM,values as'1','2','3' –
any else shud i do in the code???