RalphLeMouf Posted November 14, 2012 Share Posted November 14, 2012 (edited) Hello - I am trying to set up a forgot password system on my site. I am at the first step: which is creating a page where a person enters their email and if the email exists in the database. send them an email with a unique hashed and salted extension to verify security. I have commented out all of my steps and my logic seems to spot on, however my newness to code-igniter I may be accidentally skipping a step or something else? I am using my model to solely query the db and check against what is entered from the user. The errors I am getting are: A PHP Error was encountered Severity: Notice Message: Undefined variable: query Filename: controllers/auth.php Line Number: 142 Fatal error: Call to a member function result() on a non-object in /Users/michaelsanger/Sites/cl_ci_new/application/controllers/auth.php on line 142 however as stated above, what is wrong with my logic? //CONTROLLER function retrieve() // LOADED WHEN THE FORM IS SUBMITTED { $this->load->library('form_validation'); $this->load->library('session'); $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email'); $this->load->model('user_model', 'um'); $this->load->library('encrypt'); $this->load->helper('url'); $submit = $this->input->post('submit'); if($submit) // IF THE SUBMIT BUTTON IS SET { // START PROCESS TO CREATE $USER VARIABLE THAT HOLDS WHAT THE USER ENTERED IN THE FORM AND THAT CAN GET CHECKED AGAINST THE DB IN THE MODEL $user = $this->um->validate_retrieve(array('email' => $this->input->post('email'))); // IF THE USER IS CREATED AND CHECKS OUT AND ALL OF THE ERRORS ARE CLEARED ON THE FORM if( $user && $this->form_validation->run() == TRUE ) { $domain = "clci.dev/index.php"; // CREATE A TOKEN LINK TO SEND TO THE USERS EMAIL THAT EXIST IN THE DB AND WAS ENTERED foreach ($query->result() as $user) $token = sha1($user->email.$user->salt).dechex($user->id); $link = "http://www.".$domain."/account/confirmation/?token=$token"; { $this->load->library('email'); $this->email->from('noreply@cysticlife.org', 'CysticLife'); $this->email->to($user->email); $this->email->subject('Welcome to CysticLife!'); $this->email->message("Thanks for signing up for CysticLife! To complete the registration process please go to the following web address:\n\n$link\n\n-Your friends at CysticLife\n\nPlease remember to add the cysticlife.org domain to your address book to ensure that you receive your CysticLife e-Notifications as requested.eh"); $this->email->send(); redirect('account/welcome'); exit; } } else { $data['main_content'] = 'auth/password'; $this->load->view('includes/templates/main_page_template', $data); } } } //VIEW <div id="forget_pw_form"> <div class="forgotten_pw_text"> Please enter your email address to reset password </div> <?php echo validation_errors(); echo form_open('auth/retrieve'); echo form_label('', 'email', array('type'=>'text')); $data = array( 'name' => 'email', 'class' => 'input', 'placeholder' => 'Email' ); echo form_input($data, set_value('email')); echo form_submit('submit', 'Submit'); echo form_close(); echo "<span class='errors'>"; echo form_error('email'); echo "</span>"; ?> </div> //MODEL function validate_retrieve($data) { $query = $this->db->where($data)->get('users', '1'); if($query->row()) { return $query->row(); } } Edited November 14, 2012 by PFMaBiSmAd removed formatting to fix micro-size text Quote Link to comment https://forums.phpfreaks.com/topic/270653-what-is-wrong-with-my-logic/ Share on other sites More sharing options...
Scott_S Posted November 14, 2012 Share Posted November 14, 2012 A: labeling line #142 would be helpful potentially check your "if" in your model. I think it should be: if($query->num_rows() > 0) { return $query->row(); } Quote Link to comment https://forums.phpfreaks.com/topic/270653-what-is-wrong-with-my-logic/#findComment-1392385 Share on other sites More sharing options...
Mahngiel Posted November 15, 2012 Share Posted November 15, 2012 foreach ($query->result() as $user) Severity: Notice Message: Undefined variable: query Filename: controllers/auth.php Line Number: 142 Quote Link to comment https://forums.phpfreaks.com/topic/270653-what-is-wrong-with-my-logic/#findComment-1392502 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.