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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:55:31+00:00 2026-06-09T19:55:31+00:00

I’m attempting to create a very simple CMS with PHP and MYSQL. The problem

  • 0

I’m attempting to create a very simple CMS with PHP and MYSQL. The problem I’m having is that whenever I attempt to log in, if I put in the wrong username, what I want to happen happens. It goes to a screen that says wrong input and has a link going back to the login page. However if I put in the correct username and the wrong password it just reloads the page and if I put in the correct password, the same screen comes up as if I put in the wrong username, telling me the user name or password is wrong. I’ve checked the database to make sure the password I’m entering is correct and the username and password are both correct yet it’s not working. Can anyone help me out with this? Thank you in advance

Here are the functions that you may need to see:

function verifyUser($name, $pass)
{
// Escape strings
$username = mysql_real_escape_string($name);
$password - mysql_real_escape_string($pass);

$result = mysql_query("select * from users where username='$username' and       password-'$password' limit 1");

if (mysql_fetch_array($result))
{
    return true;
} else{
    return false;
}

}

function validateUser($name, $pass)
{
    $check = verifyUser($name, md5($pass));

    if($check)
    {
        $_SESSION['status'] = 'authorized';

        header('Location: http://localhost/cms/admin/index.php');

    } else{

        echo'Please enter a correct username and password <br />';
        echo "<a href='http://localhost/cms/admin/login.php'>Try Again?</a>";
        exit;
    }



}

Here is the login.php file:

require_once '../functions.php';

connect();

if($_POST['username'] && $_POST['password'])
{
$result = validateUser($_POST['username'], $_POST['password']);
}


?>

<form method="post" action="">
<p>
    <label for="name">Username: </label>
    <input type="text" name="username" />
</p>

<p>
    <label for="password">Password: </label>
    <input type="password" name="password" />
</p>

<p>
    <input type="submit" id="submit" value="Login" name="submit" />
</p>
</form>

I am receiving one Notice: Undefined index: username in C:\xampp\htdocs\cms\admin\login.php on line 14

  • 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-06-09T19:55:33+00:00Added an answer on June 9, 2026 at 7:55 pm

    Try adding die(); after your header('Location: ...'); line in successful login attempt.

    To correct the undefined index error, change this in login.php:

    if( isset($_POST['username']) && isset($_POST['password']) )

    Additionally, you have an error in your query. The minus sign should be an equal sign (you had password-'$password'. Unless you need to capture user data, you should try counting the results, instead of fetching them.

    $result = mysql_query("select * from users where username='$username' and       password='$password' limit 1");
    
    if ( mysql_num_rows( $result ) > 0 )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
Basically, what I'm trying to create is a page of div tags, each has

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.