It is currently Tue Feb 07, 2012 8:09 am

All times are UTC + 2 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Login form help!!
PostPosted: Thu Feb 14, 2008 9:29 am 
Offline

Joined: Mon Feb 11, 2008 11:18 am
Posts: 7
Hi all,

I created a userlogin form where it will lead to either an administrator home page or user home page. In MySQL database, i create a table named "Login" where it contains the following:
CREATE TABLE Login (
access_level INT NOT NULL,
username VARCHAR(20) NOT NULL,
password VARCHAR(25) NOT NULL,
);

and i inserted the following values as well:

INSERT INTO Login VALUES (1, 'guoxin', 'guoxinphilips');

INSERT INTO Login VALUES (2, 'jason', 'jasonphilips');

where access_level 1 represents administrator and access_level 2 represents user and i execute the sql statement in a page called "authenticate.php" which will determine either if the user is an administrator or a user:

$sql ="SELECT * FROM $table_name WHERE username = '$_POST[username]' AND password = password('$_POST[password]') AND access_level = 1";

$result = @mysql_query($sql,$connection)or die(mysql_error());

//get the number of rows in the result set
$num = mysql_num_rows($result);

//print a message or redirect elsewhere,based on result
if ($num != 0) {
header("Location: http://www.bds-net.info/alanadmin_home.html");
exit;

} else {
header("Location: http://www.bds-net.info/alan/user-home.php");
exit;
}

but the result is it just go to the administrator home page regardless of the access_level 1 or 2. So is there anyone that can help me with this problem? Thanks folks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 15, 2008 4:29 am 
Offline

Joined: Mon Feb 11, 2008 11:18 am
Posts: 7
The problem had been solved :D


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 15, 2008 4:45 am 
Offline

Joined: Sun May 02, 2004 11:34 pm
Posts: 6498
Location: toronto, canada
do a select for the name and password, then get the level and check it

Code:

$sql ="SELECT * FROM $table_name WHERE username = '".mysql_real_escape_string($_POST['username'])."'
       AND password = password('".mysql_real_escape_string($_POST[password]))."' ";

$result = mysql_query($sql,$connection)or die(mysql_error());

//get the number of rows in the result set
$num = mysql_num_rows($result);

//print a message or redirect elsewhere,based on result (should oly ever have one row returned)
if ($num == 1) {
 
  //check to see what the access level is
  if(mysql_result($result,0,'access_level')==1)
  {
    header("Location: http://www.bds-net.info/alanadmin_home.html");
    exit;
  } else {
    header("Location: http://www.bds-net.info/alan/user-home.php");
    exit;
}else{
  //no results so send the user back to the login page
  header("Location: http://www.bds-net.info/alan/login.php");   
}

_________________
Lostboy

Cat, the other other white meat

Please read Posting Etiquette before posting

You can always try Google


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 2 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron