PHP Class Question
- by Jerry
Hi all
I am trying to build a PHP class to check the username and password in MySql.
I am getting "mysql_query(): supplied argument is not a valid MySQL-Link resource in D:\2010Portfolio\football\main.php on line 38" database has errors:" message.
When I move my userQuery code out of my Class, it works fine. Only if it is inside my Class.
I am not sure if the problem is that I don't build the connection to mysql inside my Class or not. Thanks for any helps!!
Here is my code
<?php
$userName=$_POST['userName'];
$userPw=$_POST['password'];
class checkUsers {
public $userName;
public $userPw;
function checkUsers($userName='', $userPw=''){
$this->userName=$userName;
$this->userPw=$userPw;
}
function check1(){
if (empty($this->userName) || empty($this->userPw)){
$message="<strong>Please Enter Username and Password</strong>";
}else{
//line 38 is next line
$userQuery=mysql_query("SELECT userName, userPw FROM user WHERE
userName='$this->userName' and userPw='$this->userPw'", $connection);
if (!$userQuery){
die("database has errors: ". mysql_error());
}
if(mysql_num_rows($userQuery)==0){
$message="Please enter valid username and password";
}
}//end empty check
return $message;
}//end check1 method
}//end Class
$checkUser=new checkUsers($userName, $userPw);
echo $checkUser->check1();
?>
I appreciate any helps!!!!