My script is always giving me the login failed message, reguardless of weither the login info is correct or not. Here is my script:
classes/class_database.php
<?php
class database {
private $database_ip = "localhost";
private $database_username = "root";
private $database_password = "";
private $database_name = "login";
private $mysql_connection;
private $database_connection;
public function connect() {
$this->mysql_connection = mysql_connect($this->database_ip, $this->database_username, $this->database_password) or die("Failed to connect to the mysql server");
}
public function open_database(){
$this->database_connection = mysql_select_db($this->database_name, $this->mysql_connection);
}
}
?>
classes/class_user.php
<?php
class user {
private $username;
private $password;
private $email;
public function get_username() { return $this->username; }
public function get_password() { return $this->password; }
public function get_email() { return $this->email; }
public function set_username($username) { $this->username = $username; }
public function set_password($password) { $this->password = $password; }
public function set_email($email) { $this->email = $email; }
public function check_login() {
$sql = "select id from users where username = $this->username and password = md5($this->password)";
$result = mysql_query($sql);
if(!$result){
echo 'login failed!';
} else {
echo 'login successful!';
}
}
}
?>
index.php
<?php
include_once("classes/class_database.php");
include_once("classes/class_user.php");
$database = new database();
$database->connect();
$database->open_database();
$user = new user();
$user->set_username("admin");
$user->set_password("password");
$user->check_login();
?>
database:
id username password email
1 admin 5f4dcc3b5aa765d61d8327deb882cf99 bla@bla.com
Any ideas?
Michael