Currently Using CodeIgniter Framework i have an Error - php

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;
}
}
}
?>

Related

Error : Undefined property: Account::$Account_model

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

Message: Undefined index: password

Severity: Notice
Message: Undefined index: password
Filename: models/userr.php
Line Number: 10
Backtrace:
File: C:\xampp\htdocs\cooladmin\application\models\userr.php Line: 10
Function: _error_handler
File: C:\xampp\htdocs\cooladmin\application\controllers\auth.php Line:
17 Function: login
File: C:\xampp\htdocs\cooladmin\index.php Line: 315 Function:
require_once
class userr extends CI_Model {
public function login($post)
{
$this->db->select('*');
$this->db->from('user');
$this->db->where('username', $post['username']);
$this->db->where('password', $post['password']);
$query = $this->db->get();
return $query;
}
class auth extends CI_Controller
{
public function login()
{
$this->load->view('login');
}
public function process()
{
$post = $this->input->post(null, TRUE);
if(isset($post['login'])) {
$this->load->model('userr');
$query = $this->userr->login($post);
if($query->num_rows() > 0) {
echo "login berhasil !";
} else {
echo "login gagal !";
}
}
}
}
use this:
$this->db->where('password', isset($post['password']) ? $post['password'] : '');
It just means the password has not been posted from the form

codeigniter news section tutorial not working

hey guys im going thru the news section tutorial on codeigniter and i get the following error
A PHP Error was encountered
Severity: Notice
Message: Undefined property: News::$db
Filename: core/Model.php
Line Number: 77
Backtrace:
File: /Applications/MAMP/htdocs/CodeIgniter/application/models/News_model.php
Line: 13
Function: __get
File: /Applications/MAMP/htdocs/CodeIgniter/application/controllers/News.php
Line: 10
Function: get_news
File: /Applications/MAMP/htdocs/CodeIgniter/index.php
Line: 292
Function: require_once
All i did was simply copy what was provided in the tutorial, here are my files
news_model.php file
<?php
class News_model extends CI_Model {
public function __constrcut() {
$this->load->database();
}
public function get_news($slug = FALSE) {
if ($slug === FALSE ) {
$query = $this->db->get('news');
return $query->result_array();
}
$query = $this->db->get_where('news', array('slug' => $slug));
return $query->row_array();
}
}
news.php
<?php
class News extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('news_model');
}
public function index() {
$data['news'] = $this->news_model->get_news();
$data['title'] = 'News archive';
$this->load->view('templates/header',$data);
$this->load->view('news/index',$data);
$this->load->view('templates/footer');
}
public function view($slug) {
$data['news'] = $this->news_model->get_news($slug);
if (empty($data['news_item'])) {
show_404();
}
$data['title'] = $data['news_item']['title'];
$this->load->view('templates/header',$data);
$this->load->view('news/view',$data);
$this->load->view('templates/footer');
}
}
and here is a picture of my file structure
im trying my best to learn and debug but i dont know what it could be.
Maybe, database library is not loaded. you have to load database library.
application / config / autoload.php
$autoload['libraries'] = array('database');

How to Insert data to a table using codeigniter Active Record queries?

MODEL VIEW CONTROLLER PROJECT ON CODE IGNITER - UNABLE TO INSERT DATA TO THE TABLE USING Active Record Class .
ERROR
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Store::$Storemdl
Filename: controllers/Store.php
Line Number: 49
Backtrace:
File: C:\xampp\htdocs\ci\application\controllers\Store.php
Line: 49
Function: _error_handler
File: C:\xampp\htdocs\ci\index.php
Line: 292
Function: require_once
Fatal error: Call to a member function signupchk() on a non-object in C:\xampp\htdocs\ci\application\controllers\Store.php on line 49
A PHP Error was encountered
Severity: Error
Message: Call to a member function signupchk() on a non-object
Filename: controllers/Store.php
Line Number: 49
Backtrace:
MODEL
<?PHP
defined('BASEPATH') OR exit('No direct script access allowed');
function __construct ()
{
parent ::__construct();
$this->load->database();
}
function signupchk($username)
{
$this->db->select('username');
$this->db->from('users');
$this->db->where('username,$username');
$sql = $this->db->get();
if($sql && $sql->num_rows() > 0)
{
return false;
}
else
{
return true;
}
}
function signup($data)
{
$data = array(
'rusername'=> 'username',
'rpassword'=> 'password',
'remail' => 'email',
'rphone' => 'phone',
'rgender' => 'gender',
'rqualify' => 'qualification',
);
$sql = $this->db->insert('users',$data);
return $sql;
}
} ?>
CONTROLLER
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Store extends CI_Controller
{
function index()
{
$this->load->view('home');
}
function login()
{
$this->load->view('login');
}
function signup()
{
$this->load->view('signup');
}
function inserttbl(){
$username = $this->input->post('username');
$rslt = $this->Storemdl->signupchk($username);
if($result){
$this->Storemdl->signup($this->input->post());
}
else
{
echo "username already exists";
}
$this->index();
}
}
?>
post the code for model class and, in your model, change this
$this->db->where('username,$username');
to
$this->db->where('username',$username);
or
$this->db->where("username,$username");// single quote to double quote
in function signupchk($username)
Where is your model class? You can try this:
<?PHP
defined('BASEPATH') OR exit('No direct script access allowed');
class Your_model_name extends CI_Model{
function __construct ()
{
parent ::__construct();
$this->load->database();
}
function signupchk($username)
{
$this->db->select('username');
$this->db->from('users');
$this->db->where('username,$username');
$sql = $this->db->get();
if($sql && $sql->num_rows() > 0)
{
return false;
}
else
{
return true;
}
}
function signup($data)
{
$data = array(
'rusername'=> 'username',
'rpassword'=> 'password',
'remail' => 'email',
'rphone' => 'phone',
'rgender' => 'gender',
'rqualify' => 'qualification',
);
$sql = $this->db->insert('users',$data);
return $sql;
}
}
}
?>
You forget to load your model.
Add this line in your insert function:
$this->load->model('Storemdl');

Fatal error: Call to undefined method select::form() in public_html/opunletter/application/controllers/Welcome.php on line 44

I get the error :
Fatal error: Call to undefined method select::form() in public_html/opunletter/application/controllers/Welcome.php on line 44.
when i run this. what might be the reason.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function index()
{
//load the database
$this->load->database();
//load the model
$this->load->model('select');
//load the method of model
$data['h']=$this->select->select();
$data['a']=$this->select->archieve();
$data['n']=$this->select->latest();
$id=$this->input->get("id");
$data['f']=$this->select->load($id);
//return the data in view
$this->load->view('welcome_message', $data);
}
public function login()
{
$this->load->view('userlogin');
}
public function submit()
{
$data = array(
'from' => $this->input->post('from'),
'to' => $this->input->post('to'),
'title' => $this->input->post('title'),
'openletter' => $this->input->post('openletter')
);
$this->load->model('select');
//Transfering data to Model
$this->select->form($data);
}
} ?>
My model
<?php
class Select extends CI_Model
{
function __construct()
{
// Call the Model constructor
parent::__construct();
}
//we will use the select function
public function Select()
{
//data is retrive from this query
$query = $this->db->get('country');
return $query;
}
public function archieve()
{
//data is retrive from this query
$query = $this->db->query("SELECT * FROM country WHERE archieve=1;");
return $query;
}
public function latest()
{
//data is retrive from this query
$query = $this->db->query("SELECT * FROM country WHERE latest=1;");
return $query;
}
public function load($id)
{
//data is retrive from this query
$query = $this->db->select('*')
->from('country')
->where('open_id', $id)
->get();
return $query;
}
public function form($data){
// Inserting in Table(students) of Database(college)
$query = $this->db->insert('user_openletter', $data);
return $query;
}
}
?>

Categories