I am trying to write this simple class in php as follows:
<?php
session_start();
require 'db_con.php';
class logg{
private $db;
private $username = $_POST['usr_name'];
private $password = $_POST['usr_pass'];
private $query = "SELECT * FROM user WHERE nick='$username'";
function __construct(){
$this->db = new DB();
}
function loggIn(){
try{
$res = $this->db->fetch($query)
foreach($res as $row) {
$dbusername = $row['nick'];
$dbpassword = $row['pass']; }
if ($username == $dbusername && $password == $dbpassword) {
$_SESSION['username'] = $dbusername;
header('Location: index.php');
} catch (Exception $e){
echo'Wrong login information!'
}
}
}
function loggOut(){
session_destroy();
}
}
?>
but i keep getting the following error: Parse error: syntax error, unexpected '$_POST' (T_VARIABLE) and i just cant figure out why! Even if i remove theese rows:
private $username = $_POST['usr_name'];
private $password = $_POST['usr_pass'];
i instead get the following error:
( ! ) Parse error: syntax error, unexpected '"' in
im certain the error is a real simple one, but I just can't seem to figure it out..! Any help appriciated!