Hi,
I've been searching for a solution for this problem, but couldn't find anything that would help me. I get this error:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\lab2.andornagy.info\lib\core\login.php on line 15
My codes:
Login.php:
<?php
include_once("../autoload.php");
$login = new Login();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="login.php" method="get" target="_self">
<input name="login" value="true" type="hidden" />
<input name="user" type="text" />
<input name="pass" type="password" />
<input name="" type="submit" value="Login" />
</form>
<?php
if ( isset($_GET['login']) ) {
$login->DoLogin();
}
?>
</body>
</html>
The autoload works just fine.
The login.php for Login Class:
<?php
class Login extends Admin {
public function DoLogin($user = null, $pass = null) {
$user = $_GET['user'];
$pass = $_GET['pass'];
$user = mysql_real_escape_string($user);
$pass = mysql_real_escape_string($pass);
$query = "SELECT * FROM account WHERE username='$user' and password='$pass'";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
if ( $num_rows==1 ) {
echo 'Login Successfull.';
session_start();
$_SESSION['user'] = $user;
header("refresh:0;url=index.php");
} else {
die('Wrong Password or Username');
}
}
public function LoginCheck() {
session_start();
if ( isset($_SESSION['username']) ){
} else {
die(header('location:login.php'));
}
}
}