Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6983777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:27:49+00:00 2026-05-27T18:27:49+00:00

I have a mysql table called users with the following fields: username – password

  • 0

I have a mysql table called users with the following fields:

username - password - role

The role consists of normal user and admin.

What I want is so when an admin logs in it gets redirected to another page and not the same page a normal user would log in. My code is as follows:

<?php
include("../includes/db.php");

$username=$_POST['username'];
$password=$_POST['password'];

$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);

$sql="SELECT * FROM Users WHERE username='$username' and password='$password' And role = 'normaluser'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1){
session_register("username");
session_register("password");
header("location:myaccount.php");
}
?>

I have the code working for the normal user but I just don’t know how to write the code for the admin part.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:27:49+00:00Added an answer on May 27, 2026 at 6:27 pm

    I’d say

    $sql="SELECT role FROM Users WHERE username='$username' and password='$password'";
    $result=mysql_query($sql);
    while ($row = mysql_fetch_object($result)) {
        //one hit i hope?!
        //DONT save your apssword in the session!!!!
        //session_register("username");
        //session_register("password");
    
        $role = $row->role;
    
    }
    if($role == "user"){
        redirect1
    }elseif($role == "admin"){
       redirect2;
    }else{
      redirect panic
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one MySQL table, users , with the following columns: user_id (PK) email
I have a mysql table called RATING with this structure: ID, USERNAME, RATING, RATER,
I have the follwoing mysql table called user user email count ranking sss sss@gmail.com
I have a table called order_list with the following fields order_id user_id item_id count
I have a MYSQL Table with the following structure called daily_measurements +------------+----------+------+-----+---------------------+----------------+ | Field
I have a mysql table called jos_users_quizzes with the following columns: id quiz_i duser_id
I have a table called Users it contain some fields such as Id, ParentId,
I have a MySql table called reviews which stores a lot of product reviews,
I have this mysql table called comments which looks like this: commentID parentID type
I have a legacy MySQL table called lnk_lists_addresses with columns list_id and address_id .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.