Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8408647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:41:27+00:00 2026-06-09T23:41:27+00:00

im doing a PHP project using codeigniter 2.1.2 , using mySql database on WAMP,

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:41:28+00:00Added an answer on June 9, 2026 at 11:41 pm

    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();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using CodeIgniter 2.1.0 and MySQL database. I have uploaded an image through
Hi i am currently doing a school project using cakePHP. I have the following
I started doing a new project in PHP / MySql . The Aim of
I'm doing PHP development and I'm thinking of using one of these. I have
I'm doing a project for a college class I'm taking. I'm using PHP to
I'm relatively new to PHP and have been writing a project using what I
I'm a php programmer now doing a Java web project using Spring framework. I'm
For a current project I'm doing I'm using PHP includes for my nav bar
Im trying to learn php by doing a little project using apache server. I
I'm using vim with php omnicompletion on in a large project. I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.