Permite empezar de nuevo.
1. En el guión que envió, es necesario hacer este cambio, al menos:
<?
$uid=$userid;
$pwd=$userpassword;
$db=mysql_connect("localhost","###","####");
mysql_select_db("user");
// Check the staff list first
$query1="select * from staff where userid='$userid' and userpassword='$userpassword'";
$result1=mysql_query($query1);
$numrows=mysql_num_rows($result1);
if($numrows1>0)
{
$redir_url = 'search2.htm':
}
else
{
echo "<b>Login failed. Please try again<br>";
echo "<a href='login.htm'>Back To Login Page</a>";
}
// Check the student list in second place
$query2="select * from student where userid='$userid' and userpassword='$userpassword'";
$result2=mysql_query($query2);
$numrows2=mysql_num_rows($result2);
if($numrows2>0)
{
$redir_url = 'view2.htm':
}
else
{
echo "<b>Login failed. Please try again<br>";
echo "<a href='login.htm'>Back To Login Page</a>";
}
// Now we have searched the user in both tables, and we will send him to where he belongs....
// Redir user to... $redir_url
echo "<meta http-equiv='refresh' content='0;URL=".$redir_url."'>";
?>
- <?
- $uid=$userid;
- $pwd=$userpassword;
- $db=mysql_connect("localhost","###","####");
- mysql_select_db("user");
- // Check the staff list first
- $query1="select * from staff where userid='$userid' and userpassword='$userpassword'";
- $result1=mysql_query($query1);
- $numrows=mysql_num_rows($result1);
- if($numrows1>0)
- {
- $redir_url = 'search2.htm':
- }
- else
- {
- echo "<b>Login failed. Please try again<br>";
- echo "<a href='login.htm'>Back To Login Page</a>";
- }
- // Check the student list in second place
- $query2="select * from student where userid='$userid' and userpassword='$userpassword'";
- $result2=mysql_query($query2);
- $numrows2=mysql_num_rows($result2);
- if($numrows2>0)
- {
- $redir_url = 'view2.htm':
- }
- else
- {
- echo "<b>Login failed. Please try again<br>";
- echo "<a href='login.htm'>Back To Login Page</a>";
- }
- // Now we have searched the user in both tables, and we will send him to where he belongs....
- // Redir user to... $redir_url
- echo "<meta http-equiv='refresh' content='0;URL=".$redir_url."'>";
- ?>
De esta manera se busca el usuario en ambas tablas, pero esto no es una solución real.
En primer lugar, usted debe (probablemente) a todos los estudiantes y el personal de pertenecer a una mesa y utilizar un "tipo" de columna para dividirlos. ¿Qué pasa si una combinación de nombre de usuario y contraseña está presente en ambas tablas (por ejemplo: John Doe). Se trata de un funcionario o un estudiante?
No sé lo que estás haciendo, pero supongo que debe usar una sola tabla para iniciar sesión.
varchar identificador de usuario ()
varchar contraseña ()
int tipo de usuario () / / donde 1 = Estudiante, 2 = personal, 3 =...
int status () / / donde 0 = desactivado, 1 = habilitado
SELECT * FROM users WHERE userid='$userid' AND password='$password' AND status=1
Entonces, todo lo que tienes que hacer es preguntar por el valor de tipo de usuario en la fila se han encontrado para saber dónde debe ir este usuario.
<?
// Connect MySQL
$db = mysql_connect("localhost","###","####");
mysql_select_db("user");
// Check the user list
$query="SELECT * FROM users WHERE userid='$userid' AND password='$password' AND status=1'";
$result = mysql_query($query);
if (mysql_num_rows($result) > 0) {
$obj = mysql_fetch_object($result);
if ($obj->usertype == 2)
$redir_url = 'search2.htm':
if ($obj->usertype == 1)
$redir_url = 'view2.htm':
echo "<meta http-equiv='refresh' content='0;URL=".$redir_url."'>";
}
else
{
echo "<b>Login failed. Please try again<br>";
echo "<a href='login.htm'>Back To Login Page</a>";
}
?>
- <?
- // Connect MySQL
- $db = mysql_connect("localhost","###","####");
- mysql_select_db("user");
- // Check the user list
- $query="SELECT * FROM users WHERE userid='$userid' AND password='$password' AND status=1'";
- $result = mysql_query($query);
- if (mysql_num_rows($result) > 0) {
- $obj = mysql_fetch_object($result);
- if ($obj->usertype == 2)
- $redir_url = 'search2.htm':
- if ($obj->usertype == 1)
- $redir_url = 'view2.htm':
- echo "<meta http-equiv='refresh' content='0;URL=".$redir_url."'>";
- }
- else
- {
- echo "<b>Login failed. Please try again<br>";
- echo "<a href='login.htm'>Back To Login Page</a>";
- }
- ?>