Postingan lainnya
saya mendapati error ( Call to a member function row() on bool)
function index()
{
if (isset($_POST['submit'])) {
if ($this->input->post() && (strtolower($this->input->post('security_code')) == strtolower($this->session->userdata('mycaptcha')))) {
$username = $this->input->post('a', TRUE);
$password = hash("sha512", md5($this->input->post('b', TRUE)));
$cek = $this->model_app->cek_login($username, $password, 'users');
$row = $cek->row_array();
$total = $cek->num_rows();
if ($total > 0) {
$this->session->set_userdata('upload_image_file_manager', true);
$this->session->set_userdata(array(
'username' => $row['username'],
'level' => $row['level'],
'id_session' => $row['id_session']
));
redirect($this->uri->segment(1) . '/home');
} else {
echo $this->session->set_flashdata('message', '<div class="alert alert-danger"><center>Username dan Password Salah!!</center></div>');
redirect($this->uri->segment(1) . '/#');
}
} else {
echo $this->session->set_flashdata('message', '<div class="alert alert-danger"><center>Security Code salah!</center></div>');
redirect($this->uri->segment(1) . '/index');
}
} else {
if ($this->session->level != '') {
redirect($this->uri->segment(1) . '/home');
} else {
$this->load->helper('captcha');
$vals = array(
'img_path' => './captcha/',
'img_url' => base_url() . 'captcha/',
'font_size' => 17,
'img_width' => '320',
'img_height' => 33,
'border' => 0,
'word_length'
=> 5,
'expiration' => 7200
);
$cap = create_captcha($vals);
$data['image'] = $cap['image'];
$this->session->set_userdata('mycaptcha', $cap['word']);
$data['title'] = 'Users › Log In';
$this->load->view('administrator/view_login', $data);
}
}
}
1 Jawaban:
<div>Pesan kesalahan "Call to a member function row() on bool" berarti variabel $cek bukan merupakan objek. Hal ini disebabkan karena variabel $cek adalah hasil dari metode $this->model_app->cek_login(), yang mengembalikan nilai integer. Untuk mengatasi kesalahan ini, Anda perlu mengubah variabel $cek menjadi objek. Anda dapat melakukannya dengan menggunakan metode CI_DB_result::result_array(). Metode CI_DB_result::result_array() akan mengembalikan sebuah array objek, di mana setiap objek mewakili satu baris dalam database.<br><br>Berikut ini adalah kode yang telah diperbarui:<br><br><br></div><pre>function index() { if (isset($_POST['submit'])) { if ($this->input->post() && (strtolower($this->input->post('security_code')) == strtolower($this->session->userdata('mycaptcha')))) { $username = $this->input->post('a', TRUE); $password = hash("sha512", md5($this->input->post('b', TRUE))); $cek = $this->model_app->cek_login($username, $password, 'users'); $row = $cek->result_array(); $total = $cek->num_rows(); if ($total > 0) { $this->session->set_userdata('upload_image_file_manager', true); $this->session->set_userdata(array( 'username' => $row[0]['username'], 'level' => $row[0]['level'], 'id_session' => $row[0]['id_session'] )); redirect($this->uri->segment(1) . '/home'); } else { echo $this->session->set_flashdata('message', '<div class="alert alert-danger"><center>Username dan Password Salah!!</center></div>'); redirect($this->uri->segment(1) . '/#'); } } else { echo $this->session->set_flashdata('message', '<div class="alert alert-danger"><center>Security Code salah!</center></div>'); redirect($this->uri->segment(1) . '/index'); } } else { if ($this->session->level != '') { redirect($this->uri->segment(1) . '/home'); } else { $this->load->helper('captcha'); $vals = array( 'img_path' => './captcha/', 'img_url' => base_url() . 'captcha/', 'font_size' => 17, 'img_width' => '320', 'img_height' => 33, 'border' => 0, 'word_length' => 5, 'expiration' => 7200 );
$cap = create_captcha($vals);
$data['image'] = $cap['image'];
$this-&gt;session-&gt;set_userdata('mycaptcha', $cap['word']);
$data['title'] = 'Users &amp;rsaquo; Log In';
$this-&gt;load-&gt;view('administrator/view_login', $data);
}
}
}</pre>
Tanggapan
saya mendapati error baru ( Call to member function result_array()on bool