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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:06:01+00:00 2026-05-24T21:06:01+00:00

I recently experienced a very strange error. I am writing a password reset function

  • 0

I recently experienced a very strange error. I am writing a password reset function but i am experiencing a very strange error i have never experienced before. Somehow, form validation turns my query into empty array.

Here is my code:

public function password_reset()
{
    if ($this->auth_model->is_logged_in()) redirect ('welcome');

        $userid = $this->uri->segment(3);
        $code = $this->uri->segment(4);

        $this->db->select('forgot_password, id');
        $this->db->from('users');
        $this->db->limit(1);
        $this->db->where('id',$userid);
        $q = $this->db->get();

    if (!is_numeric($this->uri->segment(4, 0)) == TRUE && !is_numeric($this->uri->segment(3, 0)) == TRUE) die;

        if ($q->row('forgot_password') == $code) {

            $this->form_validation->set_rules('password', 'Password', 'required|min_length[4]');
            $this->form_validation->set_rules('confirm_password', 'Confirm', 'required|min_length[4]');

            if ($this->form_validation->run() !== false) {

                if ($this->input->post('password') != $this->input->post('confirm_password')) exit("wrong");

                $update = array (
                    'password' => sha1($this->input->post('password'))
                );

                $id = $q->row('id');

                $this->db->where('id', $id);
                $this->db->update('users', $update);
                echo $this->db->last_query();
                die; // Don't mind the last 2 lines, they were made for debugging purposes.

                echo "Password is reset";

            } $this->load->view('auth/password_reset');

        }

}

Please note this line:
$id = $q->row(‘id’);

This is where the problem begins.

If i echo this line, will get “Array”, i tried doing print_r on it but it appears to be completely empty array.

However, if i try echoing

$q->row('id');

before

if ($this->form_validation->run() !== false) {

then, i get what is expected, in my case it will be integer, but again, once form validation will be passed, it will turn my integer into empty array.

So here we are, form validation somehow turns my query row into an array.

Any help will be much appreciated.

  • 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-24T21:06:02+00:00Added an answer on May 24, 2026 at 9:06 pm

    Where you are using this:

    $q = $this->db->get();
    //...
    if ($q->row('forgot_password') == $code) {
    

    You should fetch the object using row() only once, and then reference the properties of that object, rather than call row() over and over.

    So, to get you on track to fixing this (there may be other issues with your code but we won’t know until getting past this issue), try something like this:

    $row = $this->db->get()->row();
    

    That fetches the result (the first row). Done, now you have the result stored in an object and you don’t need to fetch it again.

    Now, when you want to reference a property of that object, the value of the column in this case, you would use this:

    if ($row->forgot_password == $code) {}
    //
    $id = $row->id;
    

    And so on. Have another read through the docs for more demos: http://codeigniter.com/user_guide/database/results.html

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

Sidebar

Related Questions

I am very new to Mootools but have good experience in jQuery. Recently i
Recently I experienced very strange situation by my C program. Usually my program works
I have recently programmed a console application and I've experienced a lot of pain
I have recently started working on a very large C++ project that, after completing
I'm not very experienced in C++, and when I have to work with another
I don't have any significant experience with C++ but recently had to be involved
I have Java experience and recently am doing some C++ coding. My question is
Recently I have been investigating the possibilities of caching in ASP.NET. I rolled my
Recently, I've been dealing with an error with accessing MAPI via the .NET framework
I am very experienced in working with open-source technologies like PHP, MySQL, Apache and

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.