mysql - PHP Class Question -


I am trying to create a PHP class to check the username and password in MySql. I'm getting "mysql_query (): The supply logic is not a valid MySQL-link resource," D: \ 2010Portfolio \ football \ main.php "contains errors in the database:" message.

When I get my user code from my class, then it works fine. Only if it is inside my class, I am not sure that the problem is that I have a connection between my class or mysql connection I'm not building up. Thanks for any help! Here's my code

  & lt ;? php $ userName = $ _ POST ['username']; $ userPw = $ _ POST ['password']; class check user {public $ userName; public $ UserPw; function check user ($ user name = '', $ userPw = '') {$ this- & gt; username = $ user name; $ this-> userPw = $ userPw;} function check1 ( ) {Empty ($ the-> username)) below ($ this-> userPw) {$ message = "& lt; Strong> Please enter username and password & lt; / Strong> "else} {// line 38 next row is $ userQuery = mysql_query (" select username, userPw FROM to user WHERE user name = '$ this- & gt; username' and userPw = '$ this - (MySQL_error ($ username) =} 0) {$ message = - If you have any errors in the database ("userpw", $ connection); if (! $ Username) "Please enter a valid username and password";}} // end blank check return $ message;} // and check1 method} // end class $ checkusor = new check user ($ user name, $ userPw); echo Do $ checkUser-> Check 1 ();? & Gt;  

I appreciate any help !!!!

The problem is that your method can not see the connection object. Either your method definition (bad idea in general) in Global (

< Try to go with pre- global $ connection;

) or go with a singleton database connection (code sample) can be found on all the web).


Comments