Everything seems to work just fine but I keep getting the following error:
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: models/ordermodel.php
Line Number: 24
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: models/ordermodel.php
Line Number: 31
================================================================
In the view i just echo $company_name
Controller:
$city = $this->ordermodel->get_city($order_reference);
$customerCompanyName = $this->ordermodel->get_company_name($order_reference);
$data['company_name'] = $customerCompanyName;
Model:
function get_city($ordernumber) {
$this->db->where('order_number', $ordernumber);
$city = $this->db->get('order');
return $city->row()->city;
}
function get_company_name($ordernumber) {
$this->db->where('order_number', $ordernumber);
$companyname = $this->db->get('order');
return $companyname->row()->company_name;
}
Use therresult() method, it should elimiate all of your errors
$row = $city->result(); return $row->city;
Seem that your query has no results, try:
function get_company_name($ordernumber) {
$this->db->where('order_number', $ordernumber);
$companyname = $this->db->get('order');
if ($companyname->num_rows() > 0) {
return $companyname->row()->company_name;
}
else {
return '';
}
}
Related
I am trying to create dynamic pages in codeigniter. I m new to codeigniter.Following is my controller (Pages.php) code:
if($this->form_validation->run() == false)
{
$this->new_course();
}
else
{
$data['course_title'] = $this->input->post('pagetitle', true);
$data['course_intro'] = $this->input->post('courseintro', true);
$data['created_at'] = date('Y-m-d h:i:sa');
$data['course_slug'] = $this->seoURL($data['course_title']);
$checkPage = $this->course_model->checkPage($data);
// is page exists
if($checkPage->num_rows() > 0 )
{
customeFlash('You have already created this page', 'alert-warning', 'pages/create_course');
}
This is my Model:
public function checkPage($data)
{
return $this->db->get_where('courses',array('course_title' => $data['$data']));
}
public function add_course($data)
{
return $this->db->insert('courses', $data);
}
I am getting an error:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Pages::$course_model
Filename: controllers/Pages.php
Line Number: 53
An uncaught Exception was encountered
Type: Error
Message: Call to a member function checkPage() on null
Filename: C:\xampp\htdocs\vedacg\application\controllers\Pages.php
Line Number: 53
I dont have solid programming background, can anyone help me with this?
Edit your controller 'Pages.php' using this
$this->load->model('course_model');
$checkPage = $this->course_model->checkPage($data);
First load the course_model.php in your controller
$this->load->model('course_model');
after that you can load
$checkPage = $this->course_model->checkPage($data);
Thank you all for the help... I was doing this worng in my model:
$this->db->get_where('courses', array('course_title'=>$data['$data']));
I corrected in this:
$this->db->get_where('courses', array('course_title'=>$data['course_title']));
This is my controller function
public function check_orgn_mail()
{
$this->load->model('registrationmodel', '', TRUE);
$omail = $this->input->post('mailid');
$mailresult = $this->registrationmodel->check_org_mail();
$smil = explode("#", $omail);
$registerCompanyID = null;
if ($mailresult)
{
foreach ($mailresult as $row)
{
$registerCompanyID = $row->id;
$cmail = explode("#", $row->email);
$acmail[] = $cmail[1];
}
if (in_array($smil[1], $acmail))
{
return TRUE;
}
}
$this->form_validation->set_message('check_orgn_mail', 'Invalid Organization Mail id.');
return false;
}
This is the function in my model
function check_org_mail()
{
$this->db->select('email','id');
$this->db->from('customers');
$this->db->where('status', 1);
$query_emai = $this->db->get();
return $query_emai->result();
}
I am getting this error
Severity: Notice
Message: Undefined property: stdClass::$id Filename:
controllers/registration.php
I tried some trial and error but not working. Please help me with this. Previously it was working fine but when I checked with the different mail id, it started giving this error.
change your select to this:
$this->db->select('email, id');
You need to use
$this->db->select('email, id');
All columns are supposed be a single string argument separated by commas.
You are providing multiple arguments.
something is wrong in one of my functions. The others work fine.
The application has a MVC structure. Beginning with objects and MVC, I must ay.
Basically, I have a page (services.php) linking to:
echo"Plus d'informations...";
Function in the model page (model.php):
function get_NextServ($id)
{
global $bdd;
$id = (int)$id;
$req = $bdd->query('SELECT * FROM entreprises WHERE id= ?');
$req->execute(array($id));
return $req;
}
And the detailservices.php page:
try
{
if (isset($_GET['id']))
{
$id = intval($_GET['id']);
$billet = get_NextServ($id);
if (get_NextServ($id) < 1)
{
echo "No......";
} else
{
foreach ($billet as $data)
{
echo "<h2>" . $data['entreprise'] . "</h2>";
}
.....
I have the following errors:
Warning: Missing argument 1 for get_NextServ(), called in projects\myapp-v3\controllers\controllers.php on line 27 and defined in projects\myapp-v3\model\model.php on line 54
Notice: Undefined variable: id in projects\myapp-v3\model\model.php on line 57
Fatal error: Call to a member function execute() on a non-object in projects\myapp-v3\model\model.php on line 59
Thanks guys!
im doing a PHP project using codeigniter 2.1.2 , using mySql database on WAMP, i have stumbled upon the following problem:
Here is my model
function loadUserData() {
$sql = "SELECT username FROM user WHERE username = ?";
$query = $this -> db -> query($sql, $this->session->userdata('username'));
if ($query -> num_rows() > 0) {
foreach ($query->result() as $row) {
$data = $row;
}
return $data;
}
}
The controller
function profile_access() {
if ($this -> session -> userdata('is_logged_in')) {
$this->load-> model('profile_model');
$uData['rows']=$this->profile_model->loadUserData();
$this->load->view('profile_view',$uData);
} else {
echo "<script type=\"text/javascript\"> alert(\"You need to provide your credentials first.\");</script>";
redirect('login_controller/index');
}
}
and the view
<?php
foreach($rows as $r){
echo print_r($r);
echo $r[username]->username; //line no. 81 in my code
}
?>
the print_r($r) from view gives me the following errors:
alphaomega1
A PHP Error was encountered
Severity: Notice
Message: Use of undefined constant username - assumed 'username'
Filename: views/profile_view.php
Line Number: 81
A PHP Error was encountered
Severity: Warning
Message: Illegal string offset 'username'
Filename: views/profile_view.php
Line Number: 81
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: views/profile_view.php
Line Number: 81
I expect the above code to return only "alphaomega" which is the username in the database. it is however displayed, but i dont know why i'm getting those errors. would appreciate some help with this. thanks.
In your view:
foreach($rows as $r){
echo $r->username;
}
In your model:
function loadUserData() {
$sql = "SELECT username FROM user WHERE username = ?";
$query = $this->db->query($sql, $this->session->userdata('username'));
return $query->result();
}
I'm trying to pass along the question AND the id of the question in the first query and then with that id get that poll's options and add those to the array. Not seeing what I'm doing wronge here.
Here's the error I am getting:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_DB_mysql_result::$row
Filename: models/sitemodel.php
Line Number: 161
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: models/sitemodel.php
Line Number: 161
Code:
function getPoll() {
$this->db->select('site_polls.id, site_polls_questions.poll_question');
$this->db->from('site_polls');
$this->db->join('site_polls_questions', 'site_polls_questions.id = site_polls.site_polls_questions_id');
$this->db->where('site_polls.status_id', 1);
$this->db->order_by('site_polls.date_posted', 'desc');
$this->db->limit(1);
$query = $this->db->get();
$id = $query->row->id;
$this->db->select('site_polls_questions_options.poll_option');
$this->db->from('site_polls_questions_options');
$this->db->where('id', $id);
$query = $this->db->get();
return $query->result_array();
}
I'm trying to figure out how I can add the question of the poll into the array.
row() is a function and not a property.
$id = $query->row()->id;
or
$id = $query->row(0)->id;
$id = $query->row->id;
Should be:
$id = $query->row()->id;
$query->row() is a function, not a property.
Try this:
$query = $this->db->get()->first_row();
if ( !empty($query->id))
{
$id = $query->id;
}
else
{
return array();
}