jrws Posted December 23, 2008 Share Posted December 23, 2008 Wow, this is really peeving me off, first I find a solution to a problem and then, no more...This one is saying: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\xampp\xampp\htdocs\Website\v1\lib\classes\mysql.php on line 35 Now I don't understand why, here are two codes that interact, I have omitted the full class: function Num_Rows($sql) { $sql = $this->query($sql); $sql = mysql_num_rows($sql) or die(mysql_error()); return $sql; } and public function query($sql) { $query = mysql_query($sql) or die(mysql_error()); return $sql; } So what is it saying? Can someone instead of just giving an answer explain why it is complaining? It is spouting this error in reply to a test to add a user, the user code is: public function register($username, $password, $password2, $email) { global $Send_Email, $Admin_Email; $error = array(); $username = $this->clean($username); $username_query = "SELECT username FROM user WHERE username = '$username'"; $username_query = parent::Num_Rows($username_query); $email = $this->clean($email); $email_query = "SELECT email FROM user WHERE email = '$email'"; $email_query = $this->Num_Rows($email_query); $password = $this->clean($password); $password2 = $this->clean($password2); $password = $this->encrypt($password); //Lets start the error checking: if (checkString($username, 1, 30, 'ctype_alnum') || ($username_query > 0)) { $error[] = 'Username must be between 1 and 30 characters and alphanumeric otherwise your username is already taken.</span>'; } if (!valid_email($email) || ($email_query > 0)) { $error[] = 'Your email is invalid OR is already taken.</span>'; } if ($password !== $password2) { $error[] = 'Your passwords are not the same!</span>'; } if (count($error) > 0) { echo "The following errors occured:</br>"; foreach ($error as $err) { echo "<span style=\"color: red;\">$err"; } } else { if ($Send_Email == 1) { $subject = 'Your registration'; $message = 'This is a dummy message!'; if (mail($email, $subject, $message)) { echo 'A confirmation email has been dispatched, please check your inbox and junk mail folder.'; } else { echo 'There appears to be a problem in sending the email, please contact the administrator.'; } } else { $query = "INSERT INTO `user` (`username` ,`password` ,`email`) VALUES ('$user', '$password', '$email'); "; if (query($query)) { echo 'Congradulations you have been added to the database and can now login.'; } else { echo 'There appears to be a problem, please contact the administrator ' . $Admin_Email; } } } } If you need more of my code ask. Link to comment https://forums.phpfreaks.com/topic/138130-another-question/ Share on other sites More sharing options...
ratcateme Posted December 23, 2008 Share Posted December 23, 2008 the return value on query() should be $query not $sql? Scott. Link to comment https://forums.phpfreaks.com/topic/138130-another-question/#findComment-722079 Share on other sites More sharing options...
jrws Posted December 23, 2008 Author Share Posted December 23, 2008 Alright I will try thank you. Yes it works, thanks. Geeze I really wish I could see these simple things... Link to comment https://forums.phpfreaks.com/topic/138130-another-question/#findComment-722094 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.