Jump to content

[SOLVED] Need help please :)


AbstractFire

Recommended Posts

Hi all... I could use some help with this error I am getting.

 

This is the error I am getting:

 

Fatal error: Call to a member function on a non-object in /home/*****/public_html/sources/admin_source/class_user.php on line 35

 

This is class_user.php:

<?php
/*
+-------------------------------------------------
| AFS: Personal Blog Alpha
| (c)AbstractFire - 2007
| Add/Edit Member Check Functions
+-------------------------------------------------
| Created on 2007-05-01 2250 GMT -6
| Last Revised by: AF$
| Date of Revision: 2007-05-07
+-------------------------------------------------
*/

class class_user
{
// ===============================================
// Check the username for the requirements
// ===============================================
function checkUsername($input)
{
	$usrtest = mysql_query("SELECT username FROM mcp_logindata WHERE username = '$input'");

	// ===============================================
	// Length of the username
	// ===============================================
	if(strlen($input)<4)
	{
		$acpfunc->acpMessage("Usernames need to have at least 4 characters.");
	}

	// ===============================================
	// In use yet?
	// ===============================================
	elseif($account=mysql_fetch_assoc($usrtest))
	{
		$acpfunc->acpMessage("An account with this username already exists. Please select another one.");
	}
}

// ===============================================
// Check passwords for requirements
// ===============================================
function checkPasswords($password1, $password2)
{
	// ===============================================
	// Check the passwords to see if they are equal
	// ===============================================
	if ($password1 != $password2)
	{
		$acpfunc->acpMessage("A problem was detected with the passwords you provided. Your passwords do not match.");
	}

	// ===============================================
	// Check the length of it now
	// ===============================================
	elseif (strlen($password1) < 6)
	{
		$acpfunc->acpMessage("A problem was detected with the password you provided. Passwords must be 6 characters in length.");
	}
}

// ===============================================
// Check the email address now
// ===============================================
function checkEmail($input)
{
	if (!preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+([a-zA-Z0-9\._-] +)+$/" , $input)) 
	{
		$acpfunc->acpMessage("You provided an invalid email address");
	} 
}
}

?>

 

$acpfunc is declared in admin.php, which is located in the public_html folder. $acpfunc is another class I created that has functions specific for the ACP.

 

IN admin.php:

require("sources/admin_source/class_afunct.php");
$acpfunc = new class_afunct();

 

A little further down in admin.php, I have a little section that includes; the page that has the form that submits to userinsert.php. userinsert.php has class_user included and setup.

 

I know this may not make much sense right now. Sorry. :(

 

Thank you for any help.

Link to comment
Share on other sites

You haven't declared your constructor function yet...

 

<?php
/*
+-------------------------------------------------
| AFS: Personal Blog Alpha
| (c)AbstractFire - 2007
| Add/Edit Member Check Functions
+-------------------------------------------------
| Created on 2007-05-01 2250 GMT -6
| Last Revised by: AF$
| Date of Revision: 2007-05-07
+-------------------------------------------------
*/

class class_user
{

        // ===============================================
// Constructor
// ===============================================
        function class_user() {
            
        }

// ===============================================
// Check the username for the requirements
// ===============================================
function checkUsername($input)
{
	$usrtest = mysql_query("SELECT username FROM mcp_logindata WHERE username = '$input'");

	// ===============================================
	// Length of the username
	// ===============================================
	if(strlen($input)<4)
	{
		$acpfunc->acpMessage("Usernames need to have at least 4 characters.");
	}

	// ===============================================
	// In use yet?
	// ===============================================
	elseif($account=mysql_fetch_assoc($usrtest))
	{
		$acpfunc->acpMessage("An account with this username already exists. Please select another one.");
	}
}

// ===============================================
// Check passwords for requirements
// ===============================================
function checkPasswords($password1, $password2)
{
	// ===============================================
	// Check the passwords to see if they are equal
	// ===============================================
	if ($password1 != $password2)
	{
		$acpfunc->acpMessage("A problem was detected with the passwords you provided. Your passwords do not match.");
	}

	// ===============================================
	// Check the length of it now
	// ===============================================
	elseif (strlen($password1) < 6)
	{
		$acpfunc->acpMessage("A problem was detected with the password you provided. Passwords must be 6 characters in length.");
	}
}

// ===============================================
// Check the email address now
// ===============================================
function checkEmail($input)
{
	if (!preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+([a-zA-Z0-9\._-] +)+$/" , $input)) 
	{
		$acpfunc->acpMessage("You provided an invalid email address");
	} 
}
}

?>

Link to comment
Share on other sites

you are using treating a variable called apcfunc as an object but it is never declared as a new object.

 

If you add a constructor like the last post says dont use the name of the class for the constructor unless you are coding for php4 and i somehow doubt you are.

 

use __construct()

 

Also I think he was not using a constructor by design.....

 

and to whoever wrote this code dont use class_user as a class name, user will suffice.

 

Link to comment
Share on other sites

Yea, you are not defining $acpfunc anywhere in that class.

 

In the constructor, define it as

<?php
class user {
     var $acpfunc = null;
     // for php 5
     function __constructor() {
          $this->acpfunc = new acpfunc();
     }

     // for php 4 (note use one or the other)
     function user() {
            $this->acpfunc = new acpfunc();
     }
//....etc
}

 

Hope that helps.

Link to comment
Share on other sites

If you are coding for both, I would say make different versions. If you are not I would go with the functions users().

 

My 2 cents. Unsure if that will work with php 5 or not. Best way to find out is to test it out..

Link to comment
Share on other sites

Fatal error: Cannot instantiate non-existent class: acpfunc in /home/*****/public_html/sources/admin_source/class_user.php on line 23

 

acpfunc is included in admin.php which is in public_html. However, when I try to include it:

 

Fatal error: Cannot redeclare class class_afunct in /home/*****/public_html/sources/admin_source/class_afunct.php on line 0

 

 

Link to comment
Share on other sites

Your class doesn't retain the scope of admin.php - so the variable $acpfunc isn't recognized within the class...consider classes to be containers which have nothing to do with what's outside the container.  The only way to get variables into the container is to push them through a hole....aka an argument in a function.

 

<?php
/*
+-------------------------------------------------
| AFS: Personal Blog Alpha
| (c)AbstractFire - 2007
| Add/Edit Member Check Functions
+-------------------------------------------------
| Created on 2007-05-01 2250 GMT -6
| Last Revised by: AF$
| Date of Revision: 2007-05-07
+-------------------------------------------------
*/

class class_user
{
var $acpfunc;
        // ===============================================
// Constructor
// ===============================================
        function class_user() {
            $this->acpfunc = new class_afunct();
        }

// ===============================================
// Check the username for the requirements
// ===============================================
function checkUsername($input)
{
	$usrtest = mysql_query("SELECT username FROM mcp_logindata WHERE username = '$input'");

	// ===============================================
	// Length of the username
	// ===============================================
	if(strlen($input)<4)
	{
		$this->acpfunc->acpMessage("Usernames need to have at least 4 characters.");
	}

	// ===============================================
	// In use yet?
	// ===============================================
	elseif($account=mysql_fetch_assoc($usrtest))
	{
		$this->acpfunc->acpMessage("An account with this username already exists. Please select another one.");
	}
}

// ===============================================
// Check passwords for requirements
// ===============================================
function checkPasswords($password1, $password2)
{
	// ===============================================
	// Check the passwords to see if they are equal
	// ===============================================
	if ($password1 != $password2)
	{
		$this->acpfunc->acpMessage("A problem was detected with the passwords you provided. Your passwords do not match.");
	}

	// ===============================================
	// Check the length of it now
	// ===============================================
	elseif (strlen($password1) < 6)
	{
		$this->acpfunc->acpMessage("A problem was detected with the password you provided. Passwords must be 6 characters in length.");
	}
}

// ===============================================
// Check the email address now
// ===============================================
function checkEmail($input)
{
	if (!preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+([a-zA-Z0-9\._-] +)+$/" , $input)) 
	{
		$this->acpfunc->acpMessage("You provided an invalid email address");
	} 
}
}

?>

 

Make sure that you include the class_afunct.php first, and then this class_user.php

Link to comment
Share on other sites

Fatal error: Cannot redeclare class class_afunct in /home/*****/public_html/sources/admin_source/class_afunct.php on line 0

 

include_once did not get me anywhere and gave me the same message. Changed it to include I get this now in the constructor....

 

 

Link to comment
Share on other sites

Alright, well I guess I better post a little bit more to see if you guys can help me pin point the problem further.

 

admin.php

<?php
/*
+ --------------------------------------------------
| AFS: Personal Blog - Version 1.0 Alpha
| (c) AbstractFire - 2007
| Admin CP Main Wrapper Script
+ --------------------------------------------------
| Wrapper Revision 14$
| Last Edited on: 2007-05-06
| Edited by : 
+ --------------------------------------------------
*/

// ===============================================
// Path to all files needed
// ===============================================
$sourcepath = "sources/admin_source/";

// ===============================================
// Fetch the Main Function Class and the Admin
// Function Class - Define them too...
// ===============================================
require("sources/class_main.php");
$mainfunct = new class_main();

require($sourcepath . "class_afunct.php");
$acpfunc = new class_afunct();

// ===============================================
// Important Concept - Connect to the DB Now 
// ===============================================
$mainfunct->DatabaseConnect();

// ===============================================
// Now to fetch and include the required ACP items
// ===============================================
require($sourcepath . "session.php");
require($sourcepath . "session_open.php");

// ===============================================
// Page Array
// ===============================================
$page_array = array(NULL, 'idx', 'useraction', 'useradd', 'userform', 'userinsert', 'usermanage');

// ===============================================
// Wrapper - Header
// ===============================================
require($sourcepath. "header.php");

// ===============================================
// Wrapper - Page Includes
// ===============================================

if ($_GET['acpsection'] != "")
{
$page = htmlentities($_GET['acpsection'], ENT_QUOTES);
$page_search = array_search($page, $page_array);

if($page_search == FALSE)
{
	$mainfunct->acpError("This page is not part of the ACP.");
}

$page = $sourcepath . $page . ".php";
if (file_exists($page))
{
	include($page);
}
else
{
	$mainfunct->acpError("This page which you are trying to access does not exist.");
}
}
else
{
include $sourcepath . "idx.php";
}

// ===============================================
// Wrapper - Footer
// ===============================================
require($sourcepath. "footer.php");

?>

 

$mainfunct is the general class that does the DB connecting and SQL Injection Escape.

 

small section of class_afunct I'm trying to use. section of $class_afunct:

<?php
/*
+ --------------------------------------------------
| AFS: Personal Blog - Version 1.00 Alpha
| (c)AbstractFire - 2007
| Admin CP Function File
+ --------------------------------------------------
| Revision Status: 12$
| Last Edited on: 
| Edited by : 
+ --------------------------------------------------
*/

class class_afunct
{
// ===============================================
// Constructor
// ===============================================
function class_afunct()
{

}

// ===============================================
// General Message
// ===============================================

function acpMessage($txt)
{
	require("session.php");
	?>

<table border="0">
	<tr>
		<td><img src="images/message.gif" alt="" /></td>
		<td><h1>Personal Blog Message</h1></td>
	</tr>
	<tr>
		<td></td>
		<td><?php echo $txt; ?></td>
	</tr>
</table><br />

	<?php
	require("footer.php");
	exit();
}
}
?>

 

 

And here is a small section of class_user.

<?php
/*
+ -------------------------------------------------
| AFS: Personal Blog - Version 1.00 Alpha
| (c)AbstractFire - 2007
| Add/Edit Member Check Functions
+ -------------------------------------------------
| Created on 16 Feb, 2007 2250 GMT -6
| Last Revised by: AF$
| Date of Revision: 2007-05-09
+ -------------------------------------------------
*/

class class_user
{
var $acpfunc;

// ===============================================
// Constructor
// ===============================================
function class_user()
{
	include_once("class_afunct.php"); 		// Says cannot instantiate if using include_once and cannot redeclare if using include
	$this->$acpfunc = new acpfunc();
}       
   
// ===============================================
// Check the username for the requirements
// ===============================================
function checkUsername($input)
{
	$usrtest = mysql_query("SELECT username FROM mcp_logindata WHERE username = '$input'");

	// ===============================================
	// Length of the username
	// ===============================================
	if(strlen($input)<4)
	{
		$acpfunc->acpMessage("Usernames need to have at least 4 characters.");
	}

	// ===============================================
	// In use yet?
	// ===============================================
	elseif($account=mysql_fetch_assoc($usrtest))
	{
		$acpfunc->acpMessage("An account with this username already exists. Please select another one.");
	}
}
}
?>

 

Hopefully this is a bit better to pin point the problem.

Link to comment
Share on other sites

ok scrap my last post

 

I just need to know how to make other classes aware of the other classes so that I can use them with on top of each other.

 

I have them all included and instantiated in the main wrapper, but if I call another classes function from within another function, I have a fatal error.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.