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 &rsaquo; Log In';
            $this->load->view('administrator/view_login', $data);
        }
    }
}

avatar tumbalak
@tumbalak

1 Kontribusi 0 Poin

Diperbarui 1 tahun yang lalu

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-&gt;model_app-&gt;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-&gt;input-&gt;post() &amp;&amp; (strtolower($this-&gt;input-&gt;post('security_code')) == strtolower($this-&gt;session-&gt;userdata('mycaptcha')))) { $username = $this-&gt;input-&gt;post('a', TRUE); $password = hash("sha512", md5($this-&gt;input-&gt;post('b', TRUE))); $cek = $this-&gt;model_app-&gt;cek_login($username, $password, 'users'); $row = $cek-&gt;result_array(); $total = $cek-&gt;num_rows(); if ($total &gt; 0) { $this-&gt;session-&gt;set_userdata('upload_image_file_manager', true); $this-&gt;session-&gt;set_userdata(array( 'username' =&gt; $row[0]['username'], 'level' =&gt; $row[0]['level'], 'id_session' =&gt; $row[0]['id_session'] )); redirect($this-&gt;uri-&gt;segment(1) . '/home'); } else { echo $this-&gt;session-&gt;set_flashdata('message', '&lt;div class="alert alert-danger"&gt;&lt;center&gt;Username dan Password Salah!!&lt;/center&gt;&lt;/div&gt;'); redirect($this-&gt;uri-&gt;segment(1) . '/#'); } } else { echo $this-&gt;session-&gt;set_flashdata('message', '&lt;div class="alert alert-danger"&gt;&lt;center&gt;Security Code salah!&lt;/center&gt;&lt;/div&gt;'); redirect($this-&gt;uri-&gt;segment(1) . '/index'); } } else { if ($this-&gt;session-&gt;level != '') { redirect($this-&gt;uri-&gt;segment(1) . '/home'); } else { $this-&gt;load-&gt;helper('captcha'); $vals = array( 'img_path' =&gt; './captcha/', 'img_url' =&gt; base_url() . 'captcha/', 'font_size' =&gt; 17, 'img_width' =&gt; '320', 'img_height' =&gt; 33, 'border' =&gt; 0, 'word_length' =&gt; 5, 'expiration' =&gt; 7200 );

        $cap = create_captcha($vals);
        $data[&#039;image&#039;] = $cap[&#039;image&#039;];
        $this-&amp;gt;session-&amp;gt;set_userdata(&#039;mycaptcha&#039;, $cap[&#039;word&#039;]);
        $data[&#039;title&#039;] = &#039;Users &amp;amp;rsaquo; Log In&#039;;
        $this-&amp;gt;load-&amp;gt;view(&#039;administrator/view_login&#039;, $data);
    }
}

}</pre>

avatar adamajalah27
@adamajalah27

119 Kontribusi 40 Poin

Dipost 1 tahun yang lalu

Tanggapan

saya mendapati error baru ( Call to member function result_array()on bool

Login untuk ikut Jawaban