I've been trying to create a login for my project, but i don't know what i'm doing wrong.
This is what i use to check if the button is pressed:
if(isset($_POST['login'])){
//Get Vars
$username = $_POST['username'];
$password = md5($_POST['password']);
if(login($username, $password)){
echo 'You have been logged in';
} else {
echo 'Wrong username and password';
}
}
This is my login function:
function login($username, $password){
$db = new Database();
$query=("SELECT * FROM user
WHERE username = $username
AND password = $password");
//Bind Values
$row = $db->select($query);
-----------------------------------------
$count = mysqli_num_rows($row);
//Check Rows
if($count == 1){
setUserData($row);
return true;
} else {
return false;
}
-------------------------------------
I BELIEVE THIS IS THE PART OF THE ERROR
}
And here is my setUserData function:
function setUserData($row){
$_SESSION['is_logged_in'] = true;
$_SESSION['user_id'] = $row['id'];
$_SESSION['username'] = $row['id'];
$_SESSION['name'] = $row['name'];
}
I don't know if i need to start a session for this, and if i need to, where do i put the code.
Also how can i initialize it in the code to check, lets say, if $count works, because when i simply type echo $count, it just says Unidentified variable : count