I am trying to get variables from query and store them as cookies using this Query:
$query="SELECT id,username,password FROM employee where email='$email' AND password='$password' Limit 1";
$result= $mysqli->query($query);
if($result->num_rows == 1){
$stmt = $mysqli->prepare($query);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($user_id, $username, $db_password);
$user_browser = $_SERVER['HTTP_USER_AGENT'];
$_SESSION['user_id'] = $user_id;
//used echo to check stored variables
echo "user_id=".$_SESSION['user_id'];
//used echo here to check the query result
$_SESSION['username'] = $username;
echo "username=".$username;
$_SESSION['login_string'] = hash('sha512',
$password . $user_browser);
// Login successful.
return true;
}
else{
// Password is not correct
// We record this attempt in the database
$now = time();
$mysqli->query("INSERT INTO login_attempts(user_id, time)
VALUES ('$user_id', '$now')");
return false;
}
}
What I see in website is that:
user_id=0username=