PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
At the moment this is a simple register form. Its working properly and everything except that I need to get the user_id from the database and store it in a session. At the moment all I save in the sessions is if your logged in and the username. But I need the user_id from the database to connect it to other tables in the database. I havent programmed the best security or anything its probably pretty incomplete so forget about that atm. I just want some suggestions how I could get the user_id in a session? I am stuck at the moment.
$query = "SELECT user_id FROM user WHERE username='{$anvandarnamn}' AND password='{$password}'";
$resultLogin = mysql_query($query);
confirm_query($resultLogin);
if(mysql_num_rows($resultLogin) == 1){
$_SESSION['inloggad'] = true; //Sätter SESSIONen så man blir inloggad
$_SESSION['username'] = $anvandarnamn; //Stoppar in användarnamnet så vi kan skriva ut det på skärmen när man är inloggad
redirect_to("index.php");
}else{
$felLogin = "Du skrev in fel användarnamn eller lösenord!"; //Visar texten om man skrev fel username eller password
}
Please excuse the swedish comments I have made, just ignore them. There might be an easy solution for this but I aint that experienced programmer.