I have created a register form, that puts users in the database and auto loging in them directly after registration ( or it suppose to )
The problem is that when they register an account the autologin is redirecting the previous user that registerd.
I think its because the previous user is already loged id.. But if no one is logd in I get one of my own error message that says ” The user dont exist”
Cant really figure out whats the problem.
Any ideas ?
This is some of my code.
if(empty($errors)){
add_user($_POST['username'], $_POST['password']);
$_SESSION['uid'] = fetch_user_id($_SESSION['username']);
$_SESSION['username'] = htmlentities($_POST['username']);
header("Location: profile.php?uid=" . $_SESSION['uid']);
die();
And my function
//fetches profile information for the given user
function fetch_user_info($uid){
$uid = (int)$uid;
$sql = "SELECT
`user_name` AS `username`,
`user_email` AS `email`
FROM `users`
WHERE `user_id` = {$uid} ";
$result = mysql_query($sql);
return mysql_fetch_assoc($result);
}
You probably meant:
instead of: