Error : Undefined property: Account::$Account_model - php

A PHP Error was encountered Severity: Notice
Message: Undefined property: Account::$Account_model
Filename: Admin/Account.php
Line Number: 19
Backtrace:
File: C:\xampp\htdocs\AdminLTE\application\controllers\Admin\Account.php
Line: 19
Function: _error_handler
File: C:\xampp\htdocs\AdminLTE\index.php
Line: 292
Function: require_once
class Account extends CI_Controller {
public function _construct() {
parent::__construct();
$this->load->model('Account_model');
}
public function index() {
$mdat=[
'active_controller' => 'master',
'active_function' => 'account/account_view',
];
$this->load->view('admin/global/menu', $mdat);
$data['books']=$this->Account_model->get_all_acc();
$this->load->view('account_view',$data);
}
this is my model :
class Account_model extends CI_Model
{
var $table = 'books';
public function acc_add($data) {
$this->db->insert($this->table,$data);
return $this->db->insert_id();
}
public function get_all_acc() {
$this->db->from('books');
$query = $this->db->get();
return $query->result();
}

Try to change your function construct to this one :
public function __construct() {
parent::__construct();
$this->load->model('Account_model');
}
because the construct function require double underscore and you just typing one underscore

Related

Error Number: 1064 in deleting data using Codeigniter 3

I want to deleting my data in the table, but i can't delete the data because of this problem. Error Number: 1064
This is my Controller
class Dosen extends CI_Controller
{
public function __construct()
{
parent ::__construct();
$this->load->library('form_validation');
$this->load->model('Dosen_model');
}
public function index()
{
$data['judul'] = 'Daftar Dosen';
$data['dosen'] = $this->Dosen_model->getAllDosen();
$this->load->view('templates/header', $data);
$this->load->view('dosen/index', $data);
$this->load->view('templates/footer');
}
public function tambah()
{
$data['judul'] = 'Form tambah data Dosen';
$this->form_validation->set_rules('nip','NIP','required');
$this->form_validation->set_rules('nama','Nama','required');
if ($this->form_validation->run()==FALSE)
{
$this->load->view('templates/header', $data);
$this->load->view('dosen/tambah');
$this->load->view('templates/footer');
}
else
{
$this->Dosen_model->tambahDataDosen();
$this->session->set_flashdata('flash','Ditambahkan');
redirect('Dosen');
}
}
public function hapus($nip)
{
$this->Dosen_model->hapusDataDosen($nip);
$this->session->set_flashdata('flash','Dihapus');
redirect('Dosen');
}
And this is my Model
<?php
class Dosen_model extends CI_Model
{
public function getAllDosen()
{
$query = $this->db->get('daftar_dosen');
return $query->result_array();
}
public function tambahDataDosen()
{
$data = [
"nip" => $this->input->post('nip'),
"nama" => $this->input->post('nama'),
"prodi" => $this->input->post('prodi'),
];
$this->db->insert('daftar_dosen',$data);
}
public function hapusDataDosen($nip)
{
$this->db->where('nip',$nip);
$this->db->delete('daftar_dosen',$data);
}
}
the output is :
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: data
Filename: models/Dosen_model.php
Line Number: 23
Backtrace:
File: C:\xampp\htdocs\endtest\application\models\Dosen_model.php
Line: 23
Function: _error_handler
File: C:\xampp\htdocs\endtest\application\controllers\Dosen.php
Line: 40
Function: hapusDataDosen
File: C:\xampp\htdocs\endtest\index.php
Line: 315
Function: require_once
and then
A Database Error Occurred
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'IS NULL' at line 3
DELETE FROM daftar_dosen WHERE nip = '0001' AND IS NULL
Filename: C:/xampp/htdocs/endtest/system/database/DB_driver.php
Line Number: 691
The error message is very clear
Message: Undefined variable: data
In other words, somewhere there is a variable $data that is not defined.
Where in your code is $data found? The answer: In the function hapusDataDosen() in the call to $this->db->delete('daftar_dosen',$data);
It is hard to know exactly what you are trying to do. My guess is all you need to do is change
$this->db->delete('daftar_dosen', $data);
to
$this->db->delete('daftar_dosen');
Try this
public function hapusDataDosen($nip){
$this->db->where('nip',$nip);
$this->db->delete('daftar_dosen');
}
OR
public function hapusDataDosen($nip){
$this->db->delete('daftar_dosen', ['nip' => $nip]);
}
Don't use $data because
You are not passing it to model function
It is unnecessary to delete a record from DB
Try This --
In Model
public function hapusDataDosen($nip)
{
$this->db->where('nip',$nip);
$this->db->delete('daftar_dosen',$nip);
}
public function hapusDataDosen($nip){
$this->db->delete('daftar_dosen',array('nip'=>$nip));
}

Codeigniter :Use of undefined constant

This is my Model:
class Medecin_model extends CI_Model
{
public $fillable = array('nom','prenom','genre','adresse','date_naissance','specialiter','servise','grade','etablissement','type_personne');
public $id_medecin;
public $nom;
public $prenom;
public $genre;
public $adresse;
public $date_naissance;
public $specialiter;
public $service;
public $grade;
public $etablissement;
public $type_personne = Medecin;
public function insert($nom, $prenom, $genre, $adresse, $date_naissance, $specialiter, $service, $grade, $etablissement)
{
$this->nom=$nom;
$this->prenom=$prenom;
$this->genre=$genre;
$this->adresse=$adresse;
$this->date_naissance=$date_naissance;
$this->specialiter=$specialiter;
$this->service=$service;
$this->grade=$grade;
$this->etablissement=$etablissement;
// $this->db->insert('personne', $this);
}
This is my controller:
defined('BASEPATH') OR exit('No direct script access allowed');
class Medecin extends CI_Controller
{
public function index()
{
$this->load->view('header');
$this->load->view('ajout_medecin');
$this->load->view('footer');
}
public function ajout()
{
$this->load->model("Medecin_model");
$nom=$this->input->post('first-name');
$prenom=$this->input->post('last-name');
$genre=$this->input->post('genre');
$adresse=$this->input->post('adress');
$date_naissance=$this->input->post('birthday');
$specialiter=$this->input->post('speciality');
$service=$this->input->post('service');
$grade=$this->input->post('grade');
$etablissement=$this->input->post('establishment');
$doctor = new Medecin_model();
$doctor->insert($nom, $prenom, $genre, $adresse, $date_naissance, $specialiter, $service, $grade, $etablissement);
}
and i have this error message :
A PHP Error was encountered Severity: Notice Message: Use of undefined constant Medecin - assumed 'Medecin' Filename:
core/Loader.php Line Number: 357 Backtrace: File:
C:\wamp64\www\CodeIgniter\application\controllers\Medecin.php Line: 23
Function: model File: C:\wamp64\www\CodeIgniter\index.php Line: 315
Function: require_once
Missing '' around Medecin
Replace it
public $type_personne = Medecin;
With this
public $type_personne = 'Medecin';

Currently Using CodeIgniter Framework i have an Error

A PHP Error was encountered
Severity: Notice
Message: Undefined property: Login::$U_Model
Filename: controllers/Login.php
Line Number: 24
Backtrace:
File: C:\xampp\htdocs\Cmsproject\application\controllers\Login.php
Line: 24
Function: _error_handler
File: C:\xampp\htdocs\Cmsproject\index.php
Line: 315
Function: require_once
$data=$this->U_Model->loginf($loginf['username'], $loginf['password']);
An uncaught Exception was encountered
Type: Error
Message: Call to a member function loginf() on null
Filename: C:\xampp\htdocs\Cmsproject\application\controllers\Login.php
Line Number: 24
Backtrace:
File: C:\xampp\htdocs\Cmsproject\index.php
Line: 315
Function: require_once
Model File Is Here:
<?php
class U_Model extends CI_Model
{
public function loginf($username,$pass){
$this->db->select('*');
$this->db->from('users');
$this->db->where('username',$username);
$this->db->where('password',$pass);
if($query=$this->db->get()){
return $query->row_array();
}else{
return false;
}
}
}
?>
Hope this will help you :
Your controller should be like this :
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends CI_Controller {
public function __construct(){
parent::__construct();
//$this->load->model('User');
$this->load->helper('form');
$this->load->library('form_validation');
$this->load->helper('url');
$this->load->database();
$this->load->model('U_Model');
}
public function index(){
$this->load->view('header');
$this->load->view('login');
$this->load->view('footer');
}
/*added public before loginp*/
public function loginp(){
$username = $this->input->post('username');
$password = md5($this->input->post('password'));
/*md5 not recommended*/
$data = $this->U_Model->loginf($username, $password);
if( ! empty($data))
{
$this->session->set_userdata('sid',$data['id']);
$this->session->set_userdata('sname',$data['name']);
$this->session->set_userdata('username',$data['username']);
redirect('login/home');
}else{
$this->session->set_flashdata('emsg','Please Enter Your Correct Name And Password');
redirect('login/home');
}
}
public function home(){
$this->load->view('home');
}
}?>
Change your model like this
<?php
class U_Model extends CI_Model
{
public function loginf($username,$pass)
{
$this->db->where('username',$username);
$this->db->where('password',$pass);
$query = $this->db->get('users')
if($query->num_rows() > 0){
return $query->row_array();
}else{
return false;
}
}
}
?>
<?php
class U_Model extends CI_Model
{
public function loginf($username,$pass)
{
$this->db->where('username',$username);
$this->db->where('password',$pass);
$query = $this->db->get('users')
if($query->num_rows() > 0){
return $query->row_array();
}else{
return false;
}
}
}
?>

Fix Error Codeigniter : Call to a member function pilihkat() on a non-object

Error :
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_DB_mysqli_result::$Input_model
Filename: controllers/Input_App.php
Line Number: 18
Backtrace:
File: C:\xampp\htdocs\admin_app\application\controllers\Input_App.php
Line: 18
Function: _error_handler
File: C:\xampp\htdocs\admin_app\index.php
Line: 315
Function: require_once
and
Fatal error: Call to a member function pilihkat() on a non-object in C:\xampp\htdocs\admin_app\application\controllers\Input_App.php on line 18
My controller
class Input_App extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->model('Input_model','input_app');
}
public function index()
{
$this->db->from('referensi_kategori');
$query = $this->db->get();
$load['pilihkategori'] = $query->Input_model->pilihkat()->result();
$this->load->view('input_view',$load);
}
Model (pilihkat())
public function pilihkat(){
$this->db->select('*');
$this->db->join('referensi_kategori','referensi_kategori.id_kategori = data_aplikasi.id_kategori','left');
$query = $this->db->get();
return $query->result();
}
View (Select dropdown from data_kategori)
<tr>
<td>Kategori</td>
<td><select name="data_kategori" class="form-control"required id="data_kategori" style="width:85%;">
<option value='0'>-- pilih kategori --</option>
<?php foreach ($pilihkategori as $kat) {
echo "<option value=".$kat->id_kategori.">".$kat->data_kategori."</option>";
}?>
</select></td>
</tr>
How to fix this error ?
Load the model like this
$this->load->model('Input_model','input_model'); //here input_model is alias name
$this->load->model('Input_app','input_app'); //here input_app is alias name
(or)
$this->load->model(array('Input_model','input_app')); // pass as array mutiple modal .in below i'm using this one
remove result() in controller while calling model because in model your returning result() so in controller no need to call it again.
$load['pilihkategori'] = Input_model->pilihkat();
Controller :
public function index()
{
$load['pilihkategori'] = Input_model->pilihkat();
$this->load->view('input_view',$load);
}
Model :
public function pilihkat()
{
$this->db->select('*');
$this->db->from('referensi_kategori');
$this->db->join('referensi_kategori','referensi_kategori.id_kategori = data_aplikasi.id_kategori','left');
$query = $this->db->get();
return $query->result();
}
In your controller need to change two things.
1.Load more than one models like this.
$this->load->model(array('Input_model','input_app'));
2.Remove result() Because you already done it in model.
public function index()
{
$load['pilihkategori'] = $query->Input_model->pilihkat();
$this->load->view('input_view',$load);
}

Fatal error: Call to a member function register() on a non-object in C:\xampp\htdocs\CodeIgniter_2.1.3\application\controllers\customer.php on line 30

this is my controller class
public function _construct()
{
parent::_construct();
$this->load->model('customer_model');
}
public function create()
{
$this->load->helper('form');
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'Title', 'required');
$this->form_validation->set_rules('address', 'text', 'required');
if ($this->form_validation->run() === FALSE)
{
$this->load->helper('url');
$this->load->view('templates/header');
$this->load->view('master/customer');
}
else
{
$this->customer_model->register();
//$this->load->view('news/success');
}
}
}
and this is my moodel class
class Customer_model extends CI_model
{
public function _construct()
{
$this->load->database();
}
public function register()
{
$data = array(
'name' => $this->input->post('name'),
'address' => $this->input->post('address')
);
return $this->db->insert('registration', $data);
}
}
while running codeigniter i'm getting this error
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Customer::$customer_model
Filename: controllers/customer.php
Line Number: 30
Fatal error: Call to a member function register() on a non-object in C:\xampp\htdocs\CodeIgniter_2.1.3\application\controllers\customer.php on line 30
i'm new to codeigniter any body please tell me why this error is occuring
in controller & model, try changing:
public function _construct() {
....
}
to
public function __construct() { //double underscore
....
}

Categories