I have to get the user ID from the database, but the only session information I can get from the login page is the username and the password. I am able to get the username, but when I try to run a query to get the id using that info, it returns nothing. Here is the code:
$_SESSION['username'] = $username;
$connect = mysqli_connect("xxxx","xxxx","xxxx", "xxxx");
$IDquery = "SELECT UserID FROM User WHERE Username = ".$username.";";
$result = $connect->query("SELECT UserID FROM User WHERE Username = '$username';");
if(mysqli_num_rows($result) > 0 ){
$row = mysqli_fetch_assoc($result);
$user_id = $row["UserID"];
$_SESSION["UserID"] = $user_id;
}
How can I get the user ID if I only have the username?