-
July 18th, 2007, 10:44 AM
#1
Fatal error: Call to a member function add_user() on a non-object
I've tried working this error for 2 days now...I've look it up on google...older CodeGuru posts...kirupa...etc. So here I am posting this on here. Every bit of essential code will be posted.
The Script Calling the Error:
Code:
<?php
//check if logged in
if(!isset($_COOKIE["USERNAME"]) && !isset($_COOKIE["PASSWORD"]) && !isset($_COOKIE["GROUP"]))
{
header("location: http://www.amfol.com/finlit/login.php");
}
$logout = "http://" . $_SERVER['HTTP_HOST'] . "/finlit/logout.php";
//include_once ("../auth.php");
//include_once ("../authconfig.php");
//include_once ("../check.php");
//if not an admin...can't view
if ($check["team"] != "Admin")
{
// Feel free to change the error message below. Just make sure you put a "\" before
// any double quote.
print "<font face=\"Arial, Helvetica, sans-serif\" size=\"5\" color=\"#FF0000\">";
print "<b>Illegal Access</b>";
print "</font><br>";
print "<font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\" color=\"#000000\">";
print "<b>You do not have permission to view this page.</b></font>";
exit; // End program execution. This will disable continuation of processing the rest of the page.
}
$user = new auth();
if( is_a($user, "auth") )
echo '$user is an auth object';
else
echo "bummer";
$connection = mysql_connect($dbhost, $dbusername, $dbpass);
$SelectedDB = mysql_select_db($dbname);
$listteams = mysql_query("SELECT * from authteam");
$user = $_GET['username'];
$userinfo = mysql_query("SELECT * FROM authuser WHERE uname='$user'");
$userrow = mysql_fetch_array($userinfo);
// Get initial values from superglobal variables
// Let's see if the admin clicked a link to get here
// or was originally here already and just pressed
// a button or clicked on the User List
if (isset($_POST['action']))
{
$clientid = $userrow['clientid'];
$username = $_POST['username'];
$password = $_POST['password'];
$team = $_POST['team'];
$level = $_POST['level'];
$ssn = $_POST['ssn'];
$employer = $_POST['employer'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phoneday = $_POST['phoneday'];
$phoneeve = $_POST['phoneeve'];
$phonecell = $_POST['phonecell'];
$program = $_POST['program'];
$loanamt = $_POST['loanamt'];
$loanbal = $_POST['loanbal'];
$counselor = $_POST['counselor'];
$clientstatus = $_POST['clientstatus'];
$dateentered = $_POST['dateentered'];
$ficostart = $_POST['ficostart'];
$ficoend = $_POST['ficoend'];
$status = $_POST['status'];
$action = $_POST['action'];
$act = "";
}
elseif (isset($_GET['act']))
{
$act = $_GET['act'];
$clientid = $userrow['clientid'];
$password = $userrow['password'];
$team = $userrow['team'];
$level = $userrow['level'];
$ssn = $userrow['ssn'];
$employer = $userrow['employer'];
$address = $userrow['address'];
$city = $userrow['city'];
$state = $userrow['state'];
$zip = $userrow['zip'];
$phoneday = $userrow['phoneday'];
$phoneeve = $userrow['phoneeve'];
$phonecell = $userrow['phonecell'];
$program = $userrow['program'];
$loanamt = $userrow['loanamt'];
$loanbal = $userrow['loanbal'];
$counselor = $userrow['counselor'];
$clientstatus = $userrow['clientstatus'];
$dateentered = $userrow['dateentered'];
$ficostart = $userrow['ficostart'];
$ficoend = $userrow['ficoend'];
$status = $userrow['status'];
$action = $userrow['action'];
$action = "";
}
else
{
$action = "";
$username = "";
$password = "";
$team = "";
$level = "";
$status = "";
$action = "";
$act = "";
}
$message = "";
//MODIFY USER
if ($action == "Modify") {
$update = $user->modify_user($username, $password, $team, $level, $status, $hours, $ssn, $employer, $address, $city, $state, $zip, $phoneday, $phoneeve, $phonecell, $program, $loanamt, $loanbal, $counselor, $clientstatus, $dateentered, $ficostart, $ficoend);
$query = "SELECT * FROM authuser WHERE uname = '$username'";
$connection = mysql_connect($dbhost, $dbusername, $dbpass);
$SelectedDB = mysql_select_db($dbname);
$result = mysql_query($query);
$clientid = mysql_result($result, 0, "clientid");
if ($update==1) {
$message = "User detail updated successfully.";
}
elseif ($update == "blank level") {
$message = "Level field cannot be blank.";
$action = "";
}
elseif ($update == "sa cannot be inactivated") {
$message = "This user cannot be inactivated.";
$action = "";
}
elseif ($update == "admin cannot be inactivated") {
$message = "This user cannot be inactivated";
$action = "";
}
else {
$message = "";
}
}
// ADD USER
if ($action == "Add") {
if($_COOKIE['GROUP'] == 'Client')
{
$level = 999;
}
else if($_COOKIE['GROUP'] == 'Counselor')
{
$level = 10;
}
else
{
$level = 5;
}
$situation = $user->add_user($username, $password, $team, $level, $status, $hours,$ssn,$employer,$address,$city,$state,$zip,$phoneday,$phoneeve,$phonecell, $program,$loanamt, $loanbal,$counselor,$clientstatus,$dateentered,$ficostart,$ficoend);
$query = "SELECT * FROM authuser WHERE uname = '$username'";
$connection = mysql_connect($dbhost, $dbusername, $dbpass);
$SelectedDB = mysql_select_db($dbname);
$result = mysql_query($query);
$clientid = mysql_result($result, 0, "clientid");
echo $clientid;
echo '<br>';
if ($situation == "blank username") {
$message = "Username field cannot be blank.";
$action = "";
}
elseif ($situation == "username exists") {
$message = "Username already exists in the database. Please enter a new one.";
$action = "";
}
elseif ($situation == "blank password") {
$message = "Password field cannot be blank for new members.";
$action = "";
}
elseif ($situation == "blank level") {
$message = "Level field cannot be blank.";
$action = "";
}
elseif ($situation == 1) {
$message = "New user added successfully.";
}
else {
$message = "";
}
}
And now the script that the auth class uses...
Code:
class auth{
function add_user($username, $password, $team, $level, $status, $hours,$ssn,$employer,$address,$city,$state,$zip,$phoneday,$phoneeve,$phonecell, $program,$loanamt, $loanbal,$counselor,$clientstatus,$dateentered,$ficostart,$ficoend) {
if($team == 'Client')
{
do{
$idnum = rand(100000, 999999);
$idcheck = $this->id_check($idnum);
}while($idcheck == true);
$userExists = "SELECT * FROM authuser WHERE uname='$username'";
$query = "INSERT INTO authuser(clientid,uname,passwd,ssn,employer,address,city,state,zip,phoneday,phoneeve,phonecell,program,loanamt,loanbal,counselor,
clientstatus,team,level,status,dateentered,ficostart,ficoend,lastlogin,logincount) VALUES ('$idnum','$username',MD5('$password'),'$ssn','$employer','$address','$city','$state','$zip','$phoneday','$phoneeve','$phonecell','$program','$loanamt','$loanbal','$counselor','$clientstatus','$team','$level','$status','$dateentered','$ficostart','$ficoend','',0)";
$modquery = "INSERT INTO modules(first,last,mod1,mod2,mod3,mod4,mod5,mod6,mod7,mod8,mod9,
mod10,mod11,mod12,mod13,mod14,mod15,mod16,mod17,mod18,mod19,mod20,mod21,mod22)
VALUES ('$username',MD5('$password'), 'false', 'false', 'false', 'false', 'false',
'false', 'false', 'false', 'false', 'false', 'false', 'false', 'false', 'false',
'false', 'false', 'false', 'false', 'false', 'false', 'false', 'false',)";
$connection = mysql_connect($this->HOST, $this->USERNAME, $this->PASSWORD);
if (trim($username) == ""){
return "blank username";
}
else if (trim($password) == "")
{
return "blank password";
}
else if (trim($level) == "")
{
return "blank level";
}
$SelectedDB = mysql_select_db($this->DBNAME);
$user_exists = mysql_query($userExists);
if(mysql_num_rows($user_exists) > 0)
{
return "username exists";
}
else
{
$SelectedDB = mysql_select_db($this->DBNAME);
$setmods = mysql_query($modquery);
$result = mysql_query($query);
return mysql_affected_rows();
}
}
else
{
$qUserExists = "SELECT * FROM authuser WHERE uname='$username'";
$qInsertUser = "INSERT INTO authuser(uname, passwd, team, level, status,hourslogged, lastlogin, logincount)
VALUES ('$username', MD5('$password'), '$team', '$level', '$status', '$hours', '', 0)";
$qSetModuleDefaults = "INSERT INTO modules(first,last,mod1,mod2,mod3,mod4,mod5,mod6,mod7,mod8,mod9,
mod10,mod11,mod12,mod13,mod14,mod15,mod16,mod17,mod18,mod19,mod20,mod21,mod22)
VALUES ('$username',MD5('$password'), 'false', 'false', 'false', 'false', 'false',
'false', 'false', 'false', 'false', 'false', 'false', 'false', 'false', 'false',
'false', 'false', 'false', 'false', 'false', 'false', 'false', 'false',)";
$connection = mysql_connect($this->HOST, $this->USERNAME, $this->PASSWORD);
// Check if all fields are filled up
if (trim($username) == "") {
return "blank username";
}
// password check added 09-19-2003
elseif (trim($password) == "") {
return "blank password";
}
elseif (trim($level) == "") {
return "blank level";
}
// Check if user exists
$SelectedDB = mysql_select_db($this->DBNAME);
$user_exists = mysql_query($qUserExists);
if (mysql_num_rows($user_exists) > 0) {
return "username exists";
}
else {
// Add user to DB
// OLD CODE - DO NOT REMOVE
// $result = mysql_db_query($this->DBNAME, $qInsertUser);
// REVISED CODE
$SelectedDB = mysql_select_db($this->DBNAME);
$result = mysql_query($qInsertUser);
$setmods = mysql_query($qSetModuleDefaults);
return mysql_affected_rows();
}
}
} // End: function add_user
}//end of auth class
Can someone please tell me what the heck is going on?? $user is reconized as an object......I've even testest if $user was an auth() object.
PS: Both the modify_user and add_user produce the exact same error...I've tried looking at the parameters...but to no avail. My guess would be its a simple error and I'm just too blind to see it. Any and all help will be appreciated.
Thanks,
Raithe Davion
-
July 18th, 2007, 11:07 AM
#2
Re: Fatal error: Call to a member function add_user() on a non-object
Originally Posted by raithedavion
I've tried working this error for 2 days now...I've look it up on google...older CodeGuru posts...kirupa...etc.
Funny you mention that because simply 10 hours before your post, a user posted the exact same issue, as well as many other posters.
Call to a member function on a non-object means that the variable causing the error is one of the following.
That means that in the following line, the variable $user meets one of the above listed situations.
PHP Code:
$situation = $user->add_user($username, $password, ...
Last edited by PeejAvery; July 18th, 2007 at 11:29 AM.
Reason: Variable Correction
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
July 18th, 2007, 11:16 AM
#3
Re: Fatal error: Call to a member function add_user() on a non-object
How would I check those three?
-
July 18th, 2007, 11:36 AM
#4
Re: Fatal error: Call to a member function add_user() on a non-object
Duplicate variable declaration.
Code:
$user = new auth();
if( is_a($user, "auth") )
echo '$user is an auth object';
else
echo "bummer";
$connection = mysql_connect($dbhost, $dbusername, $dbpass);
$SelectedDB = mysql_select_db($dbname);
$listteams = mysql_query("SELECT * from authteam");
$user = $_GET['username'];
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
July 18th, 2007, 11:37 AM
#5
Re: Fatal error: Call to a member function add_user() on a non-object
Alright...$user is null. What I don't understand is how its null.....
The code for 'declaring' $user is as follows:
Code:
$user = new auth();
Now....to my understanding...that code should simply create an object called $user, of class auth. After the creation of it, you should be able to use the member functions contained within the auth class by $user->member function.
Am I wrong in my assumptions?
-
July 18th, 2007, 11:38 AM
#6
Re: Fatal error: Call to a member function add_user() on a non-object
We posted at the same time. Read my previous post.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
July 18th, 2007, 11:41 AM
#7
Re: Fatal error: Call to a member function add_user() on a non-object
OMG! See, knew it was going to be the simplest freaking fix......Thank you PeejAvery!
-
July 18th, 2007, 11:43 AM
#8
Re: Fatal error: Call to a member function add_user() on a non-object
You're most welcome.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|