I am working on a login function, but got an error that I cannot understand.
This is my Login Login class:
class Login {
private $username;
private $password;
private $cxn;
function __construct($username,$password)
{
$this->setData($username, $password);
$this->connectToDB();
}
function setData($username, $password)
{
$this->username = $username;
$this->password = $password;
}
private function connectToDB()
{
include 'Database.php';
$connect = '../include/connect.php';
$this->cxn = new database($connect);
}
function getData()
{
$query = "SELECT * FROM anvandare WHERE anvandarnamn = '$this->username' AND losenord ='$this->'password'";
$sql = mysql_query($query);
if(mysql_num_rows($sql)>0)
{
return true;
}
else
{
throw new Exception("Användarnamnet eller Lösenordet är fel. Försök igen.");
}
}
function close()
{
$this->cxn->close();
}
}
The last function gives the error "Method" close "not found in the class", "Link method not found in the topic class."
Here is my database class:
class Database {
private $host;
private $user;
private $password;
private $database;
function __construct($filename)
{
if(is_file($filename)) include $filename;
else throw new exception("Error!");
$this->host=$host;
$this->user=$user;
$this->password=$password;
$this->database=$database;
$this->connect();
}
private function connect()
{
if(!mysql_connect($this->host, $this->user, $this->password))
throw new exception("Error, not connected to the server.");
if(!mysql_select_db($this->database))
throw new exception("Error, no database selected");
}
function close()
{
mysql_close();
}
}
The paths are right, so it is not. What could be a mistake?
source
share