Hej,
jeg kan simpelthen ikke gennemskue hvorfor, at mit login ikke virker. Heller ikke når jeg hardcoder.
Fejlen ligger helt sikkert i den måde jeg prøver at hive $rows fra database class til min login class.
Database:
<?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 class:
<?php
require_once ('database.php');
class login {
public function do_login($Username, $Password)
{
global $db;
$db->fetch_rows("SELECT * FROM user_table WHERE Username=" . $Username . " AND Password=" . $Password . "");
if (($db->rows) != null)
{
(bool)$_SESSION['loggedIn'] = true;
(string)$_SESSION['uID'] = $db->rows['ID'];
(string)$_SESSION['Firstname'] = $db->rows['Firstname'];
(string)$_SESSION['Surname'] = $db->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');
$Username = isset($_POST['Username']);
(string)$Password = isset($_POST['Password']);
if (isset($_POST['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>
Håber i kan hjælpe
Indlæg senest redigeret d. 25.01.2010 16:33 af Bruger #14181