Message: Undefined index: password - php

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

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

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

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

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');

Categories