AbstractFire Posted May 8, 2007 Share Posted May 8, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/50565-solved-need-help-please/ Share on other sites More sharing options...
per1os Posted May 8, 2007 Share Posted May 8, 2007 Where is line 35 located, display that plus at least 20 above and 20 below to get more efficient and better help. Quote Link to comment https://forums.phpfreaks.com/topic/50565-solved-need-help-please/#findComment-248550 Share on other sites More sharing options...
JakeTheSnake3.0 Posted May 8, 2007 Share Posted May 8, 2007 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"); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/50565-solved-need-help-please/#findComment-248552 Share on other sites More sharing options...
Nameless12 Posted May 8, 2007 Share Posted May 8, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/50565-solved-need-help-please/#findComment-248554 Share on other sites More sharing options...
AbstractFire Posted May 8, 2007 Author Share Posted May 8, 2007 how would I use _construct() exactly? And I kinda wish for this script to work on php4 or php5, not be php5 exclusive. frost110: I made a mistake, its line 28. Which is $acpfunc->acpMessage("Usernames need to have at least 4 characters."); Quote Link to comment https://forums.phpfreaks.com/topic/50565-solved-need-help-please/#findComment-248559 Share on other sites More sharing options...
per1os Posted May 8, 2007 Share Posted May 8, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/50565-solved-need-help-please/#findComment-248562 Share on other sites More sharing options...
AbstractFire Posted May 8, 2007 Author Share Posted May 8, 2007 Would I put both in the class to make work on php4 and 5? Quote Link to comment https://forums.phpfreaks.com/topic/50565-solved-need-help-please/#findComment-248575 Share on other sites More sharing options...
per1os Posted May 8, 2007 Share Posted May 8, 2007 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.. Quote Link to comment https://forums.phpfreaks.com/topic/50565-solved-need-help-please/#findComment-248577 Share on other sites More sharing options...
JakeTheSnake3.0 Posted May 8, 2007 Share Posted May 8, 2007 You could just make two separate class files....one for php4 and the other for php5... class folder |_php4 |_class.user.php |_php5 |_class.user.php Quote Link to comment https://forums.phpfreaks.com/topic/50565-solved-need-help-please/#findComment-248581 Share on other sites More sharing options...
AbstractFire Posted May 8, 2007 Author Share Posted May 8, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/50565-solved-need-help-please/#findComment-248585 Share on other sites More sharing options...
JakeTheSnake3.0 Posted May 8, 2007 Share Posted May 8, 2007 shouldn't it be class.user.php not class_user.php? Quote Link to comment https://forums.phpfreaks.com/topic/50565-solved-need-help-please/#findComment-248591 Share on other sites More sharing options...
trq Posted May 8, 2007 Share Posted May 8, 2007 Use include_once not include. Quote Link to comment https://forums.phpfreaks.com/topic/50565-solved-need-help-please/#findComment-248597 Share on other sites More sharing options...
AbstractFire Posted May 8, 2007 Author Share Posted May 8, 2007 the name of the file is class_user.php Sorry if that wasn't clarified. Quote Link to comment https://forums.phpfreaks.com/topic/50565-solved-need-help-please/#findComment-248598 Share on other sites More sharing options...
JakeTheSnake3.0 Posted May 8, 2007 Share Posted May 8, 2007 Save the actual class file as "class.class_user.php" then. Quote Link to comment https://forums.phpfreaks.com/topic/50565-solved-need-help-please/#findComment-248604 Share on other sites More sharing options...
AbstractFire Posted May 8, 2007 Author Share Posted May 8, 2007 What would that exactly do for the script? Quote Link to comment https://forums.phpfreaks.com/topic/50565-solved-need-help-please/#findComment-248607 Share on other sites More sharing options...
trq Posted May 8, 2007 Share Posted May 8, 2007 What would that exactly do for the script? Nothing. You can name the script whatever you like. Did you try include_once() to get rid of your last error? Quote Link to comment https://forums.phpfreaks.com/topic/50565-solved-need-help-please/#findComment-248611 Share on other sites More sharing options...
JakeTheSnake3.0 Posted May 8, 2007 Share Posted May 8, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/50565-solved-need-help-please/#findComment-248613 Share on other sites More sharing options...
AbstractFire Posted May 8, 2007 Author Share Posted May 8, 2007 What would that exactly do for the script? Nothing. You can name the script whatever you like. Did you try include_once() to get rid of your last error? Yes. Still the same. Quote Link to comment https://forums.phpfreaks.com/topic/50565-solved-need-help-please/#findComment-248616 Share on other sites More sharing options...
AbstractFire Posted May 9, 2007 Author Share Posted May 9, 2007 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.... Quote Link to comment https://forums.phpfreaks.com/topic/50565-solved-need-help-please/#findComment-248677 Share on other sites More sharing options...
AbstractFire Posted May 9, 2007 Author Share Posted May 9, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/50565-solved-need-help-please/#findComment-249382 Share on other sites More sharing options...
AbstractFire Posted May 10, 2007 Author Share Posted May 10, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/50565-solved-need-help-please/#findComment-249465 Share on other sites More sharing options...
AbstractFire Posted May 10, 2007 Author Share Posted May 10, 2007 fixed... I was missing $this when calling the functions in the classes. Quote Link to comment https://forums.phpfreaks.com/topic/50565-solved-need-help-please/#findComment-249521 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.