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 7415795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:22:11+00:00 2026-05-29T07:22:11+00:00

why is my error message not showing if password or username is incorrect? i

  • 0

why is my error message not showing if password or username is incorrect? i would like an error message displayed if the user enters the wrong username or password

code can be seen below

<?php

// Inialize session
session_start();

// Include database connection settings
include('connect.inc');

// Retrieve username and password from database according to user's input
$login = mysql_query("SELECT * FROM users WHERE (username = '" . mysql_real_escape_string($_POST['username']) . "') and (password = '" . mysql_real_escape_string(md5($_POST['password'])) . "')");

// Check username and password match
if (mysql_num_rows($login) == 1) {
        // Set username session variable
        $_SESSION['username'] = $_POST['username'];
    }
    else
    {
    // Invalid login
    echo "Your username or password are incorrect!";
}

        // Jump to secured page
           $row = mysql_fetch_array($login);

switch ($row['drop']):
    case yes:
        header('Location: choose1.php');
        exit;
    case no:
        header('Location: choose2.php');
        exit;


}
else {

        header('Location: login.php');


}

?>
  • 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-29T07:22:11+00:00Added an answer on May 29, 2026 at 7:22 am

    write case value in ' also break in switch case

    case 'yes':
            header('Location: choose1.php');
            exit; // this line shouldn't be needed but it's good practice
            break;
    
    case 'no':
            header('Location: choose2.php');
            exit;
            break;
    

    better way:

    <?php session_start();
    require_once('connect.inc');
    
    // Retrieve username and password from database according to user's input
    $input_username = mysql_real_escape_string($_POST['username']);
    $login = mysql_query("SELECT * FROM users WHERE username = '".$input_username."'" );
    
    // Check username and password match
    $row = mysql_fetch_array($login);
    if (mysql_num_rows($login)) {
            if($row['password'] === md5($_POST['password'])){
                 $_SESSION['username'] = $_POST['username']; // store in session
                 switch ($row['drop']){
                        case 'yes': header('Location: choose1.php'); break;
                        case 'no': header('Location: choose2.php'); break;
                    }
                         exit;
            }
            else {
                echo "Wrong username and password combination";
                exit;
            }       
    }
    else{
            // Invalid login
            echo "Invalid Unsername";
            header('Location: login.php');
            exit;
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get the following error message in SQL Server 2005: User '<username>' does not
I got this error message and I'm not quite sure whats wrong: Exception in
The following code does not want to compile. See the included error message. Code:
I am getting unexpected T_TRY, expecting T_FUNCTION error message and am not sure as
This is not an actual Xcode error message, it is a warning that has
I get this error message in Eclipse: Access restriction: The type DirectoryWalker is not
I am getting an error message, and I not quite sure where the issue
I'm currently getting a Could not load type UI.Administration.Site.master error message and I'm not
I am receiving a CoreData could not fulfill a fault for ... error message
I get this message when compiling C++ on gcc 4.3 error: ‘NULL’ was not

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.