PHP forums, MySQL forums, Web Development resources

Home PageHome    PHP ResourcesTopic List    FAQFAQ    SearchSearch    MemberlistMemberlist    UsergroupsUsergroups 
 RegisterRegister
    ProfileProfile    Log in to check your private messagesLog in to check your private messages    Download the RSS Reader RSS Feed Download the RSS Reader RSS for this forum Log inLog in 

PHP Forum :: MySQL Forum :: Java Script Forum



Login form help!!

 
Post new topic   Reply to topic    WeberForums.com Forum Index -> MySQL General
View previous topic :: View next topic  
Author Message
guoxin



Joined: 11 Feb 2008
Posts: 7

PostPosted: Thu Feb 14, 2008 8:29 am    Post subject: Login form help!! Reply with quote

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
Back to top
View user's profile Send private message
guoxin



Joined: 11 Feb 2008
Posts: 7

PostPosted: Fri Feb 15, 2008 3:29 am    Post subject: Reply with quote

The problem had been solved Very Happy
Back to top
View user's profile Send private message
lostboy



Joined: 02 May 2004
Posts: 5128
Location: toronto, canada

PostPosted: Fri Feb 15, 2008 3:45 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail AIM Address MSN Messenger
Display posts from previous:   
WeberTrivia Questions WeberTrivia Questions
 Think you are smart? Prove it!. Try your skills with these questions :
 WeberTrivia QuestionsRecursive arrays and multi-dimensional arrays are one and the same. (PHP and MySQL)
 WeberTrivia QuestionsThe \"cache_dir\" tag of the squid configuration has a default of /var/spool/squid. (Linux)

WeberTrivia Questions



PHP Code Examples
 Stream diffrent sizes of images from a single image to save disk space.
 JavaScript dropdown list menu to switch any page.
 Dump the contents of a PHP variable in html format with a recursive list of subfolders and files from a given root directory.
 PHP Dump in html format the contents of one array variable with a recursive list of the nested array variables inside.
 Link Extractor - This function is used to extract links from a given URL. This will convert relative path into absolute path and also remove PHPSESSID stuff.
 Building a Dynamic Form using Javascript and innerHTML. Add form elements in realtime without refreshing the page.
 A PHP Calendar function with CSS : add a cool calendar to any php page by just adding a calendar class based function.
Post new topic   Reply to topic    WeberForums.com Forum Index -> MySQL General All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
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
You cannot vote in polls in this forum






Powered by phpBB © 2001, 2005 phpBB Group
PHP Forum :: MySQL Forum :: Java Script Forum