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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:45:58+00:00 2026-05-26T08:45:58+00:00

this ought to be simple, but it doesn’t seem to be working for me.

  • 0

this ought to be simple, but it doesn’t seem to be working for me. i have tested it with good and bad passwords. no matter what, it will not go into the else statement. i am not sure what i am missing

my code:

$mysqli = mysqli_connect("localhost", "joeuser", "somepass", "testDB");

 if (mysqli_connect_errno()) {
      printf("Connect failed: %s\n", mysqli_connect_error());
      exit();
  } else {
      $sql = "SELECT * FROM login_info";      
      $res = mysqli_query($mysqli, $sql);

  if ($res) {
      while ($newArray = mysqli_fetch_array($res, MYSQLI_ASSOC)) {
          $id  = $newArray['first_name'];                          
          $testField = $newArray['last_name'];                      
          echo "The ID is ".$id." and the text is ".$testField."<br/>";
         }
  } else {
      printf("Could not retrieve records: %s\n", mysqli_error($mysqli));
  }

        mysqli_free_result($res);
        mysqli_close($mysqli);
  }

If i send it a user and password that do exist it does the if statement fine, but if i send it a test for one that is not in the db it still won’t do the else? why?

  • 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-26T08:45:59+00:00Added an answer on May 26, 2026 at 8:45 am

    Like this:

    if ($res) {
          while ($newArray = mysqli_fetch_array($res, MYSQLI_ASSOC)) {
              $id  = $newArray['first_name'];                          
              $testField = $newArray['last_name'];                      
              echo "The ID is ".$id." and the text is ".$testField."<br/>";
             }
    }
    
    if (!isset($id)) {
          printf("Could not retrieve records: %s\n", mysqli_error($mysqli));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This ought to simple. Say we have a struct from a library that doesn't
This ought to be simple but I just can't figure this one out: The
This seems like it ought to be simple, but I've tried both try {}
This ought to be very simple in Rails, but I'm still learning... My code
This ought to be pretty simple, maybe use a regex but I would think
It seems this ought to be dead simple, but I'm stuck. I've written some
Ought I to unit test constructors? Say I have a constructor like this: IMapinfoWrapper
This might seem like a stupid question I admit. But I'm in a small
I have two simple while loops in my program that I feel ought to
This is a bit of a long shot, but if anyone can figure it

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.