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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:10:52+00:00 2026-05-21T02:10:52+00:00

Im trying to test a pin number in the database compared to one entered

  • 0

Im trying to test a pin number in the database compared to one entered by a user, whenever i run it i get a ‘Trying to get property on non-object’ error … I cant seem to spot where im going wrong, could someone please help me out … Its saying the error is on the $thepin = $pins->pin; line

The code i have in my controller is as follows:

function check_pin()
{
$pin = md5($this->input->post('oldpin'));
$email = $this->input->post('email');

$existingpin = $this->users->get_pin_by_email($email);
foreach($existingpin as $pins){
    $thepin = $pins->pin;
}

if($pin != $thepin){
    $this->form_validation->set_message('check_pin', 'The Old Pin Number does not match the existing one');
    return FALSE;
} else {
    return TRUE;
}
}

and the following is the code in my model

function get_pin_by_email($emailaddress)
{
$this->db->where('LOWER(email)=', strtolower($emailaddress));
$query = $this->db->get($this->table_name);
if ($query->num_rows() == 1) return $query->row();
return NULL;
}
  • 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-21T02:10:53+00:00Added an answer on May 21, 2026 at 2:10 am

    The Controller code should be:-

    function check_pin()
    {
      $pin = md5($this->input->post('oldpin'));
      $email = $this->input->post('email');
    
      $existingpin = $this->users->get_pin_by_email($email);
      foreach($existingpin as $pins){
        // Check for the NULL return
        if ($pins != NULL && is_object($pins)) {
          $thepin = $pins->pin;
        }
      }
    
      if($pin != $thepin){
        $this->form_validation->set_message('check_pin', 'The Old Pin Number does not match the existing one');
        return FALSE;
      } else {
        return TRUE;
      }
    }
    

    If you look closely in the model code, you will find that you are returning two data types – one is Object & another is NULL. So in your controller code, you should also check that accordingly.

    Hope it helps.

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

Sidebar

Related Questions

Im trying to test my successfully creates a new user after login (using authlogic).
Trying to test to see if a user is logged in I am using
I am trying to test a class that manages data access in the database
I am trying to test a proof of concept that I can run a
I'm trying to test if a number is greater than 0 but less than
I'm trying to test a simple SQLite database using Robolectric in my Android application.
Im trying to get a hit test/overlap test to work in the below code
I am trying to get data from database for Google charts in my program.
just trying to test for equality in this piece of code, but getting a
I trying to test an AccountController that uses DotNetOpenAuth but I am running into

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.