Sorry, old discussion is closed...! Using $this when not in object context
11-11-2010, 02:58 AM
|
Sorry, old discussion is closed...! Using $this when not in object context
|
Posts: 3
Name: sylvain m
|
Using php 5.2.13
PHP Fatal error: Using $this when not in object context in
/home/xxx/public_html/xxxactex/x/lib/User.class.php on line 227
I have a hard time understanding "object context" right now
It's easier for me to understand HTML...
I intentionaly broke the lines arround line 227.
There goes the code :
PHP Code:
function listUsers($start=0, $count, $order ='user_lastname', $dir='ASC'){ $sql = new MySQL_class(); $sql->Create();
$users = array();
$qry = ' SELECT u.user_id, u.user_firstname, ' . ' u.user_lastname, u.user_email, u.user_status,' . ' u.user_created ' . ' FROM tblUsers u ' . ' ORDER BY ' . $order . ' ' . $dir . ' LIMIT ' . $start . ',' . $count ; $sql->Query($qry); if($sql->err_no != 0){
*****line 227[COLOR=black]*** [/COLOR] [COLOR=black]$this->err_no = $sql->err_no;[/COLOR]
$this->err_msg = $sql->err_msg; }
for($i=0; $i<$sql->rows; $i++){ $sql->Fetch($i);
$user = new User();
$user->user_id = $sql->data['user_id']; $user->user_lastname = $sql->data['user_lastname']; $user->user_firstname = $sql->data['user_firstname']; $user->user_email = $sql->data['user_email']; $user->user_created = $sql->data['user_created']; $user->user_status = $sql->data['user_status']; $users[$i] = $user; } return($users); }
Thanx for your help.
Last edited by chrishirst; 11-11-2010 at 08:01 PM..
|
|
|
|
11-11-2010, 03:02 AM
|
Re: Sorry, old discussion is closed...! Using $this when not in object context
|
Posts: 22
Name: Martin
|
User pastebin or some similar site to paste all the User.class.php
It's ok for now to replace this:
$this->err_msg = $sql->err_msg;
with this:
$err_msg = $sql->err_msg;
This way your site will work, but errors will not be shown.
|
|
|
|
11-11-2010, 03:14 AM
|
Re: Sorry, old discussion is closed...! Using $this when not in object context
|
Posts: 9
Name: sean chow
Location: china
|
class User_Class_Name extends .... {
public $err_no = 0;
public $err_msg = NULL;
function listUsers($start=0, $count, $order ='user_lastname', $dir='ASC'){
.....
if($sql->err_no != 0){
$this->err_no = $sql->err_no;
$this->err_msg = $sql->err_msg;
}
....
}
}
__________________
icq#: 637540642
msn: Please login or register to view this content. Registration is FREE
Last edited by sean1984; 11-11-2010 at 03:15 AM..
|
|
|
|
11-11-2010, 06:51 AM
|
Re: Sorry, old discussion is closed...! Using $this when not in object context
|
Posts: 3
Name: sylvain m
|
Thanx for the replies.
Here's the complet user.class.php code...
here's also what sean1984 gave in reply.
PHP Code:
class User_Class_Name extends .... {
public $[COLOR=black]err_no[/COLOR] = 0; public $err_msg = NULL;
function listUsers($start=0, $count, $order ='user_lastname', $dir='ASC'){
.....
if($sql->err_no != 0){ [COLOR=black]$this->err_no = $sql->err_no;[/COLOR] $this->err_msg = $sql->err_msg; } ....
}
}
May you tell me where the above parts go ?
I feel terrible for asking so much, and thanx again :(
<?php
require_once('Db.class.php'); require_once('Forms.class.php');
class User{
var $user_id = 0; var $user_firstname = ''; var $user_lastname = ''; var $user_email = ''; var $user_password = ''; var $user_telephone = ''; var $user_fax = ''; var $user_address = ''; var $user_address2 = ''; var $user_city = ''; var $user_state = ''; var $user_country = 'US'; var $user_postcode = ''; var $user_created = 0; var $user_status = 0; var $err_no = 0; var $err_msg = '';
function User($id=0){
if($id > 0){
$sql = new MySQL_class(); $sql->Create();
$row = $sql->QueryRow('SELECT * FROM tblUsers WHERE user_id = ' . $id . ' LIMIT 1');
if($sql->err_no == 0){ $this->user_id = $row['user_id']; $this->user_firstname = $row['user_firstname']; $this->user_lastname = $row['user_lastname']; $this->user_email = $row['user_email']; $this->user_password = $row['user_password']; $this->user_telephone = $row['user_telephone']; $this->user_fax = $row['user_fax']; $this->user_address = $row['user_address']; $this->user_address2 = $row['user_address2']; $this->user_city = $row['user_city']; $this->user_state = $row['user_state']; $this->user_country = $row['user_country']; $this->user_postcode = $row['user_postcode']; $this->user_created = $row['user_created'];; $this->user_status = $row['user_status']; }else{ $this->err_no=$sql->err_no; $this->err_msg = $sql->err_msg; } return ($sql->err_no); } return (0); }
function insertUser(){
$sql = new MySQL_class(); $sql->Create();
$qry = 'INSERT INTO tblUsers ( user_firstname, ' . ' user_lastname, ' . ' user_email, ' . ' user_password, ' . ' user_telephone, ' . ' user_fax, ' . ' user_address, ' . ' user_address2, ' . ' user_city, ' . ' user_state, ' . ' user_country, ' . ' user_postcode, ' . ' user_created, ' . ' user_status) ' . ' VALUES ( ' . prepStr(ucwords($this->user_firstname)) . ', ' . prepStr(ucwords($this->user_lastname)) . ', ' . prepStr($this->user_email) . ', ' . prepStr($this->user_password) . ', ' . prepStr($this->user_telephone) . ', ' . prepStr($this->user_fax) . ', ' . prepStr(ucwords($this->user_address)) . ', ' . prepStr(ucwords($this->user_address2)) . ', ' . prepStr(ucwords($this->user_city)) . ', ' . prepStr($this->user_state) . ', ' . prepStr($this->user_country) . ', ' . prepStr(strtoupper($this->user_postcode)) . ', ' . time() . ', ' . 1 . ')'; $sql->Insert($qry); $this->user_id = $sql->lastid; if($sql->err_no != 0){ $this->err_no = $sql->err_no; $this->err_msg = $sql->err_msg; } return($this->err_no); }
function updateUser(){ $sql = new MySQL_class; $sql->Create();
$qry = ' UPDATE tblUsers SET ' . ' user_firstname = ' . prepStr(ucwords($this->user_firstname)) . ', ' . ' user_lastname = ' . prepStr(ucwords($this->user_lastname)) . ', ' . ' user_email = ' . prepStr($this->user_email) . ', ' . ' user_password = ' . prepStr($this->user_password) . ', ' . ' user_telephone = ' . prepStr($this->user_telephone) . ', ' . ' user_fax = ' . prepStr($this->user_telephone) . ', ' . ' user_address = ' . prepStr(ucwords($this->user_address)) . ', ' . ' user_address2 = ' . prepStr(ucwords($this->user_address2)) . ', ' . ' user_city = ' . prepStr(ucwords($this->user_city)) . ', ' . ' user_state = ' . prepStr($this->user_state) . ', ' . ' user_country = ' . prepStr($this->user_country) . ', ' . ' user_postcode = ' . prepStr(strtoupper($this->user_postcode)) . ', ' . ' user_status = ' . prepStr($this->user_status) . ' WHERE user_id = ' . $this->user_id . ' LIMIT 1'; $sql->Update($qry); if($sql->err_no != 0){ $this->err_no = $sql->err_no; $this->err_msg = $sql->err_msg; } return ($sql->err_no); }
function deleteUser(){
$sql = new MySQL_class(); $sql->Create(); $qry = ' DELETE FROM tblUsers WHERE user_id = ' . $this->user_id . ' LIMIT 1'; $sql->Delete($qry); if($sql->err_no != 0){ $this->err_no = $sql->err_no; $this->err_msg = $sql->err_msg; } return ($sql->err_no); }
function validateRegForm(){ $err = 0; if(strlen(trim($this->user_firstname)) == 0) $err += 1; if(strlen(trim($this->user_lastname)) == 0) $err += 1; if(!Forms::validateEmail($this->user_email)) $err +=1; return($err); }
function userName($id=0){ if($id == 0){ $id = $this->user_id; } $sql = new MySQL_class(); $sql->Create(); $qry = 'SELECT user_firstname, user_lastname FROM tblUsers WHERE user_id = ' . $id; $row = $sql->QueryRow($qry); $name = $row['user_firstname'] . ' ' . $row['user_lastname']; return ($name); }
function swapLongCountryName(){ // Create an SQL object $sql = new MySQL_class; $sql->Create(); $this->user_country = $sql->QueryItem('SELECT countries_name FROM tblCountries WHERE countries_iso_code_2 = \'' . $this->user_country . '\' LIMIT 1'); }
function swap2LetterStateAbbrev(){ // Create an SQL object $sql = new MySQL_class; $sql->Create(); $abbrev = $sql->QueryItem('SELECT states_abbrev FROM tblStates WHERE states_name = \'' . $this->user_state . '\' LIMIT 1'); if($sql->rows > 0){ $this->user_state = $abbrev; } }
function idFromEmail($email=''){ // Create an SQL object $sql = new MySQL_class; $sql->Create();
$id = $sql->QueryItem('SELECT user_id FROM tblUsers WHERE user_email = \'' . $email . '\' LIMIT 1'); return ($id); }
function listUsers($start=0, $count, $order ='user_lastname', $dir='ASC'){ $sql = new MySQL_class(); $sql->Create();
$users = array();
$qry = ' SELECT u.user_id, u.user_firstname, ' . ' u.user_lastname, u.user_email, u.user_status,' . ' u.user_created ' . ' FROM tblUsers u ' . ' ORDER BY ' . $order . ' ' . $dir . ' LIMIT ' . $start . ',' . $count ; $sql->Query($qry); if($sql->err_no != 0){ $this->err_no = $sql->err_no; $this->err_msg = $sql->err_msg; }
for($i=0; $i<$sql->rows; $i++){ $sql->Fetch($i);
$user = new User();
$user->user_id = $sql->data['user_id']; $user->user_lastname = $sql->data['user_lastname']; $user->user_firstname = $sql->data['user_firstname']; $user->user_email = $sql->data['user_email']; $user->user_created = $sql->data['user_created']; $user->user_status = $sql->data['user_status']; $users[$i] = $user; } return($users); }
function totalUsers(){ $sql = new MySQL_class(); $sql->Create();
$qry=' SELECT COUNT(1) as total FROM tblUsers'; $total = $sql->QueryItem($qry); return ($total); }
function searchUsers($key='', $start=0, $count, $order ='user_lastname', $dir='ASC'){ $sql = new MySQL_class(); $sql->Create();
$users = array();
// get total count $qry = ' SELECT COUNT(1) as total' . ' FROM tblUsers ' . ' WHERE (LOWER(user_firstname) LIKE LOWER(\'%' . $key . '%\')) ' . ' OR (LOWER(user_lastname) LIKE LOWER(\'%' . $key . '%\')) ' . ' OR (LOWER(user_email) LIKE LOWER(\'%' . $key . '%\')) '; $this->total_count = $sql->QueryItem($qry);
//Run the search $qry = ' SELECT u.user_id, u.user_firstname, ' . ' u.user_lastname, u.user_email, u.user_status,' . ' u.user_created ' . ' FROM tblUsers u ' . ' WHERE (LOWER(user_firstname) LIKE LOWER(\'%' . $key . '%\')) ' . ' OR (LOWER(user_lastname) LIKE LOWER(\'%' . $key . '%\')) ' . ' OR (LOWER(user_email) LIKE LOWER(\'%' . $key . '%\')) ' . ' ORDER BY ' . $order . ' ' . $dir . ' LIMIT ' . $start . ',' . $count ; $sql->Query($qry); if($sql->err_no != 0){ $this->err_no = $sql->err_no; $this->err_msg = $sql->err_msg; }
for($i=0; $i<$sql->rows; $i++){ $sql->Fetch($i);
$user = new User();
$user->user_id = $sql->data['user_id']; $user->user_lastname = $sql->data['user_lastname']; $user->user_firstname = $sql->data['user_firstname']; $user->user_email = $sql->data['user_email']; $user->user_created = $sql->data['user_created']; $user->user_status = $sql->data['user_status']; $users[$i] = $user; } return($users);
}
} ?>
Last edited by chrishirst; 11-11-2010 at 08:00 PM..
|
|
|
|
11-11-2010, 08:16 AM
|
Re: Sorry, old discussion is closed...! Using $this when not in object context
|
Posts: 147
|
How do you call this listUsers function?
If you are calling it as static then you will see the error you have.
PS. If you are coding on php 5.2.13 you have to pay attention to the class rules.
You have to specify public, private or protected methods for your variables and functions.
And you have errors in your function declarations. (ex):
Code:
function listUsers($start=0, $count, $order ='user_lastname', $dir='ASC'){
The variable in red should be defined too if previous variable predefined.
|
|
|
|
11-11-2010, 08:23 PM
|
Re: Sorry, old discussion is closed...! Using $this when not in object context
|
Posts: 9
Name: sean chow
Location: china
|
Veter, You have said exactly!
__________________
icq#: 637540642
msn: Please login or register to view this content. Registration is FREE
|
|
|
|
11-11-2010, 09:43 PM
|
Re: Sorry, old discussion is closed...! Using $this when not in object context
|
Posts: 3
Name: sylvain m
|
I'm too newbie for this, I'm gone.
Poor little me, my first language is french. What a shame.
|
|
|
|
|
« Reply to Sorry, old discussion is closed...! Using $this when not in object context
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|