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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:39:35+00:00 2026-06-10T00:39:35+00:00

I am getting errors saying $id1 and $id2 are undefined. Am I not accessing

  • 0

I am getting errors saying $id1 and $id2 are undefined. Am I not accessing them right? If not how do I access them correctly?

$query = $this->db->query("SELECT * FROM churchMembers");
$row = $query->row();
    if ($query->num_rows() != 0) {
      if ($postingUserId == $row->cMuserId) { // check to see what church the posting user is a member of
        $id1 = $row->cMchurchId; // if posting user is a member of a church set it to var id1
      } 
      if ($userid == $row->cMuserId) { // check to see what church myuserid is a member of
        $id2 = $row->cMchurchId; // if myuserid is a member of a church set it to var2
      } 
      if ($id1 == $id2) { // if posting user and myuserid are a member of the same church process the following
        echo json_encode(array('loggedIn' => true, 'isMembershipSame' => true));
      } 
      elseif ($id1 != $id2) { // if posting user and myuserid are not a member of the same user process the following
        echo json_encode(array('loggedIn' => true, 'isMembershipSame' => false));
      }
    }
  • 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-10T00:39:37+00:00Added an answer on June 10, 2026 at 12:39 am

    You don’t define either $id1 or $id2 unless their corresponding if conditions are met, so if either of the preceding conditions is false and doesn’t run, neither variable exists when you attempt to compare them in if ($id1 == $id2).

    You should initialize them to empty strings before entering your if chain. Then when you compare them, also verify that they are non-empty:

    // ADDENDUM after comments:
    // If you put this into a loop to fetch rows,
    // the following must be INSIDE the loop to reinitialize
    // the two vars on each iteration.
    
    // Initialize them as empty strings
    $id1 = "";
    $id2 = "";
    
    // If you are in a loop, you should check num_rows() once outside the loop, rather than inside
    if ($query->num_rows() != 0) {
      if ($postingUserId == $row->cMuserId) {
        $id1 = $row->cMchurchId;
      } 
      if ($userid == $row->cMuserId) {
        $id2 = $row->cMchurchId;
      } 
      // Test if they are non-empty (conditions matched above) and equal:
      if (!empty($id1) && !empty($id2) && $id1 == $id2) {
        echo json_encode(array('loggedIn' => true, 'isMembershipSame' => true));
      } 
      // No need for else if here, just a plain else clause
      else {
        echo json_encode(array('loggedIn' => true, 'isMembershipSame' => false));
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hmm.. I am getting an errors saying the constructor is undefined. Dele.setOnClickListener(new OnClickListener() {
I recently got an email from a customer saying that they were getting errors
I keep getting an error saying that @android:style/Widget.Holo.Light.Button.Borderless is not public and so can't
We're getting a server error saying Parameter count does not match Parameter Value count.
i have this php code and keep on getting errors upon fixing each error.
I'm trying to parse this string into java, but I keep getting errors. {id:1,jsonrpc:2.0,result:{limits:{end:3,start:0,total:3},sources:[{file:/media/storage/media/re
I am trying to install FAAC on linux. I'm getting errors. I use this
I am getting a compile error, saying that the copy constructor of the scoped_ptr
I'm getting errors and warnings that seem to indicate that 4th edition examples are
Im a getting errors from some code developed in Java that want to use

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.