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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:32:30+00:00 2026-06-04T00:32:30+00:00

I’m ripping my noob hair out here. Can’t understand why below code isn’t working.

  • 0

I’m ripping my noob hair out here. Can’t understand why below code isn’t working. The page loads alright, but when I try to log in with the username and password that is in my database the page is just reloaded to its original state with the login form, when I’d actually like to see a logout button instead. I’ve also tried comparing the password without salt and hash with an unhashed, unsalted equivalent in the database. Not working.

The only warnings I get are “It is not safe to rely on the system’s timezone settings.”, and I don’t think those have anything to do with the password verification functionality.

The page starts out like this:

session_start();

error_reporting(-1); ini_set('display_errors', 'On');

Then follows some HTML. Then:

if (isset($_POST['log_out'])) {
    session_unset();
    session_destroy();
    $_SESSION = array();
}

The logout button, when pressed, sets $_POST['log_out']. Then comes a function I got from a book, used to prevent SQL injection:

function mysql_fix_string($string) {
    if (get_magic_quotes_gpc()) $string = stripslashes($string);
    $string = htmlspecialchars($string, ENT_QUOTES);
    $string = mysql_real_escape_string($string);
    return $string;
}

Then comes the password verification part, which should only run if the user has submitted the login form (which posts back to the same page, thus setting $_POST['username'] and $_POST['password']):

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

    $salt1 = 'how';
    $salt2 = 'pony';
    $password = md5($salt1 . $_POST['password'] . $salt2);

    $db_hostname = 'xxxxxxxxx';
    $db_username = 'xxxxxxxxx';
    $db_password = 'xxxxxxxxx';
    $db_database = 'xxxxxxxxx';

    $db_server = mysql_connect($db_hostname, $db_username, $db_password);

    if (!$db_server) die("Unable to connect to MySQL: " . mysql_error());

    mysql_select_db($db_database)
        or die("Unable to select database: " . mysql_error());

    $username = mysql_fix_string($_POST['username']);

    $query = "SELECT password FROM users WHERE name = '" . $username . "'";

    $result = mysql_fetch_assoc($query);
    $passwordindatabase = $result['password'];

    if ($password == $passwordindatabase) {
        $_SESSION['logged_in'] = true;
        $_SESSION['user'] = $username;
        unset($_POST['username']);
        unset($_POST['password']);
    }

}

A bit further down comes the login form, only shown if ($_SESSION['logged_in'] != true). It posts the values of the input fields username and password to $_SERVER['REQUEST_URI'] (the same page).

  • 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-04T00:32:31+00:00Added an answer on June 4, 2026 at 12:32 am

    Looks to me like you’re missing the mysql_query() function which means you aren’t actually executing the query.

    mysql_query — Send a MySQL query

    Do the following and see if it works:

    $result = mysql_query($query);
    
    $passwordindatabase = mysql_fetch_assoc($result);
    

    Edit
    On a completely different note, you should not use mysql functions since they are quite old fashioned and have mysql_injection vulnerability. I would advice you to start working with PDO as soon as possible, which (if done right) has got no mysql_injection vulerabilities.

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

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.