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));
}
}
You don’t define either
$id1or$id2unless their correspondingifconditions are met, so if either of the preceding conditions is false and doesn’t run, neither variable exists when you attempt to compare them inif ($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: