View Single Post
Old 05-02-2005, 06:00 AM   #4 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,693
redhead is on a distinguished road
Just noticed your first error in this:
PHP Code:
$result=mysql_query("SELECT * FROM tutor 
  WHERE username='" 
$username "' and password='" $password "'"); 

$row=mysql_fetch_array($result); 
$num=mysql_num_rows($result); 

// print login form and exit if failed. 
if($num 1){ 
  
session_destroy(); 
  echo 
"You are not authenticated.  Please login.<br><br>"
  exit; 

at this point every student login will fail.
PHP Code:
$result=mysql_query("SELECT * FROM tutor 
  WHERE username='" 
$username "' and password='" $password "'"); 

$row=mysql_fetch_array($result); 
$num=mysql_num_rows($result); 

if(
$num 1){ 
   
$result=mysql_query("SELECT * FROM student 
    WHERE username='" 
$username "' and password='" $password "'"); 

    
$row=mysql_fetch_array($result);
    
$num=mysql_num_rows($result); 
    if(
$num 1){ // print login form and exit if failed. 
        
session_destroy(); 
        echo 
"You are not authenticated.  Please login.<br><br>"
        exit; 
    } 

    if (
$row['username']==$username
    { 
       
// we have a student 
       
$fullname=$row['firstname'] . ' ' $row['lastname']; 
       echo(
"Hello Student: $fullname<p>"); 
       echo(
'done');     
       if (
$row['password']==$password
       { 
             
// we have an authenticated student 
             
echo("Student you have logged in correctly"); 
       } 
       else 
       { 
          echo (
"try again");
       }     
    } 

else

    
// We have a tutor 
    
$fullname=$row['firstname'] .' ' $row['lastname']; 
    echo(
"Hello tutor: $fullname<p>"); 
    if (
$row['password']==$password
     { 
     
// we have an authenticated tutor 
     
echo("Tutor you have logged in correctly"); 
     } else { echo (
"try again");}     
   }

$loggedin=true
might be a better aproach.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote