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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:41:47+00:00 2026-05-27T21:41:47+00:00

I’ve looked at similar questions posted here as well as did a basic Google

  • 0

I’ve looked at similar questions posted here as well as did a basic Google search but the best I could find is about why W3Schools is a horrible place to learn from which didn’t help much with my problem. I don’t necessarily want a solution, I’d prefer an explanation as to why this isn’t working as I have had a similar problem in the past but worked around since this is me simply debugging and testing other sections of code.

To begin with, I’ve got a pesky echo inside an if statement that isn’t printing, the funny thing is that neither the if, nor the else block appear to be executed.

My index.php file:

<!DOCTYPE html>
<html>
    <head>
        <title>A Title</title>
    </head>

    <body>
        <?php
            session_start();

            include "scripts/Employee.php";

            error_reporting(E_ALL);

            $user = new Employee('bbuck', 'password');

            echo "<p>I have some stuff that works here.</p>";

            if (!($user->error() === false)) {
                echo "<p>Authenticated!</p>";
            }
            else {
                echo $user->error();
            }
        ?>
    </body>
</html>

The Employee constructor:

public function __construct($username, $password) {
    $db = Database::getInstance();

    $result = $db->authenticate($username, $password);
    if ($result !== false) {
        $this->id = $result['id'];
        $this->fname = $result['fname'];
        $this->lname = $result['lname'];
        $this->lastAction = $result['last_action'];
        $this->error = false;
    }
    else
        $this->error = "Failed to authenticate the user, wrong username/password combination.";
}

I don’t think it’s really important, but just as a reference the Employee::error() function is simply return $this->error;.

And finally, the Database::authenticate() function:

public function authenticate($username, $password) {
    $query = "SELECT * FROM `employee` WHERE `username` = '" 
        . $this->conn->escape_string($username) 
        . "' AND `password` = PASSWORD('"
        . $this->conn->escape_string($password) . "')";

    $result = $this->conn->query($query);

    if (!$result)
        return false;

    $rowCount = $result->num_rows;

    if ($rowCount == 1) {
        $row = $result->fetch_assoc();
        $update = "UPDATE `employee` SET `session_id` = UUID(), `session_expires` = (NOW() + INTERVAL 10 MINUTE) WHERE `id` = {$row['id']}";
        $select = "SELECT `session_id`, `session_expires` FROM `employee` WHERE `id` = {$row['id']}";

        $updateResult = $this->conn->query($update);

        if (!$updateResult)
            die("Failed to update the employee!");

        $updateResult = $this->conn->query($select);

        if (!$updateResult)
            die("Failed to pull Session data for employee!");

        $updateRow = $updateResult->fetch_assoc();
        $_SESSION[SESSION_ID] = $updateRow['session_id'];
        $_SESSION[SESSION_EXPIRES] = new DateTime($updateRow['session_expires']);

        return $row;
    }

    return false;
}

Now, the echo statements within the if/else block of index.php are not printing anything, I’ve used var_dump on $user and $user->error() === false and both gave me the results that I expected to receive from them. I’ve also placed an echo before the if statement and it worked, as well as one after the statement, it also worked. I’m confused as to why they are being overlooked.

This is for debugging, I’m trying to test code, but as I said, I’m curious why this is being skipped because I’ve encountered this before.

  • 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-27T21:41:47+00:00Added an answer on May 27, 2026 at 9:41 pm

    I’m not sure if this is the full extent of your problem, but your conditions aren’t correct.

    if (!($user->error() === false)) {
        echo "<p>Authenticated!</p>";
    }
    else {
        echo $user->error();
    }
    

    The echo $user->error(); inside the else statement will only ever execute if $user->error() === false. In this case you will be executing echo false;, which will give you no echoed output.


    To resolve this problem, use this instead (assuming $user->error(); returns false if no errors exist):

    if ($user->error() === false) {
        echo "<p>Authenticated!</p>";
    }
    else {
        echo $user->error();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to construct a data frame in an Rcpp function, but when I
I'm making a simple page using Google Maps API 3. My first. One marker

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.