jrws Posted December 27, 2008 Share Posted December 27, 2008 Hi guys, me again. I have a fatal error of Call to a member function on a non-object How do you fix these errors? The specific error that it is saying is about the mysql_num_rows function called Num_Rows; here's the code for it <?php function Num_Rows($sql) { $sql = $this->query($sql); $sql = mysql_num_rows($sql) or die(mysql_error()); return $sql; } ?> And here is a snippit of the code in use (specifically the problem) <?php require_once ('../inc/config.php'); $db = new mysql(); //....... //This is in a class mind you: $username_query = "SELECT username FROM user WHERE username = '$username'"; $username_queryR = $db->Num_Rows($username_query); $email = $this->clean($email); $email_query = "SELECT email FROM user WHERE email = '$email'"; $email_queryR = $db->Num_Rows($email_query); ?> The question is how do I fix this problem and any future problems such as this? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted December 27, 2008 Share Posted December 27, 2008 well you have used the OOP notation with no visible instantiation of an object... you need to pass the dabase obect in too!!!! Why have you wriiten a function to do what a method already available to you can do???? Why are you using $this outside a class???? what are you doing? Quote Link to comment Share on other sites More sharing options...
jrws Posted December 27, 2008 Author Share Posted December 27, 2008 No idea, I am new to PHP and programing in general, trying random stuff. I know my logic is way off, What do you mean by pass the database object? edit: The num_rows function is inside a class. And what do you mean by there is already a method? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted December 27, 2008 Share Posted December 27, 2008 <?php require_once ('../inc/config.php'); $db = new mysql(); //....... //This is in a class mind you: $username_query = "SELECT username FROM user WHERE username = '$username'"; $username_queryR = $db->query($username_query); echo $username_queryR->num_rows; $email_query = "SELECT email FROM user WHERE email = '$email'"; $email_queryR = $db->query($email_query); echo $email_queryR->num_rows; ?> what do you mean to achieve with this line? $email = $this->clean($email); answer to question 1. Not being funny but you need to know about scope if you are going to code - even at a basic level.... question 2. you should read up on classes and OOP and learn what a 'method' is... Quote Link to comment Share on other sites More sharing options...
jrws Posted December 27, 2008 Author Share Posted December 27, 2008 A method is a function no? And the point of cleaning the emai is to prevent unsanitary user input. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted December 27, 2008 Share Posted December 27, 2008 A method is a function no? well no not really - in this ocntext a method belongs to an object - something you can perform on that object. AN object (or an instance of a class) needs to be aware of what it can do - this is done by declaring these methods within the objects template (the class). Unless you have coded something like <?php class Myclass { private $foo; protected function__construct() { $this->foo = 'Initiated'; } private function bar () { echo $this->foo; } } ?> get some books or read some stuff on PHP OOP and you will pick it up v quickly... Doubt anyone on here will teach you to code!!!! And the point of cleaning the emai is to prevent unsanitary user input. you need something to clean before you call a 'clean' on it and where is the method 'clean' defined? again this will come... Quote Link to comment Share on other sites More sharing options...
jrws Posted December 27, 2008 Author Share Posted December 27, 2008 In the user class. It takes the arguments given, $user, $pass1, $pass2, $email. It then uses these to perform the rest of the script. I was thinking that the arguments would be from the form users submit, therefore making the $user = $_POST['user'; etc Quote Link to comment 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.