Tak for hjælpen, men det virker stadig ikke.
istedet for at extend classen, kunne du bare kalde den vha. new.. fx.:
class login{
private $Database;
public function do_login($Username, $Password)
{
$this->Database = new database();
$this-Database->FunktionIDatabaseklasse();
}
}
Jeg skal jo stadig extende min class for at kunne bruge rows, der er protected.
Den siger stadig:
"Login failed, you typed a wrong username or password!"
Dette er som det ser ud nu:
Database klasse:
<?php
class database
{
private $connectlink; //Database Connection Link
private $username = "root";
private $password = "";
private $database = "*********";
private $hostname = "localhost";
private $resultlink; //Database Result Recordset link
protected $rows; //Stores the rows for the resultset
function __construct()
{
$this->connectlink = mysql_connect($this->hostname,$this->username,$this->password);
if(!($this->connectlink))
{
//throw new DatabaseConnectionException("Error Connecting to the Database".mysql_error(),"101");
}
else
{
mysql_select_db($this->database);
}
}
function __destruct()
{
@mysql_close($this->connectlink);
}
public function query($sql)
{
$this->resultlink = mysql_query($sql);
return $this->resultlink;
}
public function fetch_rows($sql)
{
$result = $this->query($sql);
$rows = array();
if($result)
{
while($row = mysql_fetch_array($result))
{
$rows[] = $row;
}
}
else
{
//throw new RetrieveRecordsException("Error Retrieving Records".mysql_error(),"102");
$rows = null;
}
return $rows;
}
}
$db = new database(); //Create database object
?>
login klasse:
<?php
require_once ('database.php');
class login extends database {
Private $Database;
public function do_login($Username, $Password)
{
$this->Database = new database();
$this->Database->fetch_rows("SELECT * FROM user_table WHERE Username=" . $Username . " AND Password=" . $Password . "");
if ($this->Database->rows != null)
{
(bool)$_SESSION['loggedIn'] = true;
(string)$_SESSION['uID'] = $this->Database->rows['ID'];
(string)$_SESSION['Firstname'] = $this->Database->rows['Firstname'];
(string)$_SESSION['Surname'] = $this->Database->rows['Surname'];
(string)$error = null;
header(" location:membersite.php ");
}
else
{
(bool)$_SESSION['loggedIn'] = false;
(string)$error = "Login failed, you typed a wrong username or password!";
return $error;
}
}
public function do_logout()
{
Unset($_SESSION['loggedIn']);
Unset($_SESSION['uID']);
Unset($_SESSION['Firstname']);
Unset($_SESSION['Surname']);
}
}
$login = new login();
?>
login side:
<?php
require_once('classes/login.php');
(string)$Username = isset($_POST['Username']);
(string)$Password = isset($_POST['Password']);
if (isset($_POST['logIn']))
{
$login = new login();
echo $login->do_login($Username, $Password);
}
?>
<html>
<head>
</head>
<body>
<div>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="POST">
<div style="float:left;">Username:</div>
<div><input type="text" name="Username" /></div>
<div style="float:left;">Password:</div>
<div><input type="text" name="Password" /></div>
<div><input type="submit" name="logIn" value="Log In" /></div>
</form>
</div>
</body>
</html>