-3

PLEASE HELP OUT, AM NEW AT THIS... GETTING THIS LOGIN ERROR WHEN EVER A CLIENT LOGIN...A PHP Error was encountered

Severity: Notice

Message: Undefined variable: number

Filename: controllers/Site.php

Line Number: 42

Backtrace:

File: /home/rocketmoney/public_html/application/controllers/Site.php Line: 42 Function: _error_handler

File: /home/rocketmoney/public_html/index.php Line: 315 Function: require_once

HERE IS MY CONTROLLER CODES

<?php
if ($this->form_validation->run()) {
    if ($this->core_model->login()) {
        $query = $this->db->get_where('users', array('number' => $number));
        $result = $query->row_array();
        $name = $result['name'];
        $bank_details = $result['bank_details'];
        $session_data = array('number' => $_POST['number'], 'loggedin' => TRUE, 'name' => $name);
        $this->session->set_userdata($session_data);
        redirect(site_url('dash'));
    }
}?>
Rushil K. Pachchigar
  • 1,263
  • 2
  • 21
  • 40

1 Answers1

0

Firstly this is a risky code because what if $result array is null? what if $result array doesn't have name and bank_details index?

By the way, if you are just concern only about the error you are getting, then: Before your if condition just add the following line:

$number = isset($number) ? $number : '';

This line will set the number variable with the previous number variable is it exist otherwise it will put empty string on that number variable. Your provided code doesn't give any hint whether the number variable is being set above this code. So if it isn't set then what are you checking in the where condition? You are getting the error. So, this line should solve this compilation error but you may still have any logical error.

Imran
  • 4,582
  • 2
  • 18
  • 37