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

  • Home
  • SEARCH
  • 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 7060547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:21:57+00:00 2026-05-28T04:21:57+00:00

What is the problem with following code? Please help me out. I want to

  • 0

What is the problem with following code? Please help me out.

I want to match admin-id and password from the database along with login-id and password of the normal users and further want to transfer the control to the respective forms.

When I run this code it gives following errors:

Notice: Undefined variable: userstatus in C:\xampp\htdocs\xampp\Test\HRMS\extract.php on line 25

Notice: Undefined variable: usertype in C:\xampp\htdocs\xampp\Test\HRMS\extract.php on line 30

$query1="select user_type,user_staus from `user_info` where name='$username' and  
password='$password'";
$fetched=mysql_query($query1);

while($record=mysql_fetch_assoc($fetched))
{
    while(each($record))
    { 
        $usertype=$record["user_type"];
        $userstatus=$record["user_staus"];
    }//closing of 1st while loop
}//closing of 2nd while loop

if($userstatus==1) //if is logged in already
{
    echo "Please login after some time";
    exit();
}

if($usertype == 0) // if user is not an admin
{
    $query1="select * from `user_info` where name='$username' and  password='$password'";
    $result = mysql_query($query1);
    if(mysql_num_rows($result) == 1) 
    {
        header("Location: user_form.php");
    }
}
else if($usertype == 1) //if the user is a normal user
{
    header("Location: admin_form.php");
}
else 
{
    echo "please register to login";
}   

Can someone help me find the problem?

  • 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-28T04:21:58+00:00Added an answer on May 28, 2026 at 4:21 am

    There are many problems with your code, main reason you receiving an error is because $usertype and $userstatus are not predefined and not validated.
    But in my opinion it is not a main issue with your code.

    There are few questions that I would like to ask you:

    • Why creating two loops if you need to fetch a single row?
    • Why querying database twice if you already know the answer?
    • Are you escaping $username and $password for bad characters using mysql_real_escape_string method?

    here is an example how this code should look like:

    $query1 = "SELECT user_type,user_staus FROM `user_info` WHERE name='{$username}' AND password='{$password}' LIMIT 1";
    
    $fetched = mysql_query($query1);
    
    //check if record exists otherwise you would receive another notice that can 
    //break redirect functionality
    if (mysql_num_rows($fetched))
    {
        $record = mysql_fetch_assoc($fetched);
    
        // make sure that value is integer
        if ((int)$record["user_staus"])
        {
            exit("Please login after some time");
        }
        else
        {
            $url = (bool)$record["user_type"] ? 'admin_form.php' : 'user_form.php';
    
            header("Location: {$url}");
    
            exit(0);
        }
    
    }
    else
    {
        echo "please register to login";
    }
    

    UPDATE
    As suggested by nikc.org, removed 3rd level if nesting and replaced with ternary comparison

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

am new here. i have a slight problem; PLease look at the following code
I have the following code: The actual problem is the non-quoted code. I want
Somebody please help me out. This problem is killing me. I went through tones
I have a problem with the following code: for(i = 0;(i - 1)< n;i++)
I personally have no problem with the following code if (Object foo != null
I am experiencing a problem with the following code in some versions of Internet
I have a problem with the following code: protected void onDraw(Canvas canvas) { Paint
I dont understand what would be the problem with the following code. It needs
i am new in JSP,i have some problem with the following code : <%@
The following code demonstrates a weird problem I have in a Turbo C++ Explorer

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.