User Profile with your login system.

Post here is you are having problems with any of the tutorials.
hys
Posts: 38
Joined: Fri Jan 20, 2012 11:11 am

Re: User Profile with your login system.

Post by hys »

waiting for jacek to look at code :)
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: User Profile with your login system.

Post by jacek »

hys wrote:waiting for jacek to look at code :)
It all looks very fine and neat except for this little bit
function fetch_current_user_id($username){
$username = mysql_real_escape_string($username);
$sql = 'SELECT `user_id` FROM `users` WHERE `user_name` = '{$username}'';
 
$result = mysql_query($sql);
 
return mysql_result($result, 0);
 
}
 
if(empty($_SESSION['uid'])) {
$_SESSION['uid'] = fetch_current_user_id($_SESSION['username']);
 
}
So lets neaten that up
function fetch_current_user_id($username){
	$username = mysql_real_escape_string($username);
	
	$sql = 'SELECT `user_id` FROM `users` WHERE `user_name` = '{$username}'';
	$result = mysql_query($sql);
	
	return mysql_result($result, 0);
}

if(empty($_SESSION['uid'])){
	$_SESSION['uid'] = fetch_current_user_id($_SESSION['username']); 
}
Now, you should can calling the function in the init file (not in the function definition file) once you have stored the username in the session.

There is also a fairly obvious syntax error on this line, which you should be able to spot :)
$sql = 'SELECT `user_id` FROM `users` WHERE `user_name` = '{$username}'';
Image
hys
Posts: 38
Joined: Fri Jan 20, 2012 11:11 am

Re: User Profile with your login system.

Post by hys »

Can it be this?
$sql = 'SELECT `user_name` FROM `users` WHERE `user_id` = '{$username}'';
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: User Profile with your login system.

Post by jacek »

No, you want to query the username, I'll just tell you :) It should be this
    $sql = "SELECT `user_id` FROM `users` WHERE `user_name` = '{$username}'";
Image
hys
Posts: 38
Joined: Fri Jan 20, 2012 11:11 am

Re: User Profile with your login system.

Post by hys »

Omg :d and i couldt see that hehe sorry for that mate :D

i have a question more how much code do i have to make if i want to see when users are online ? like when u click user list then u see the name " Bob (online)" .

Hys
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: User Profile with your login system.

Post by jacek »

Quite a lot ;)
Image
hys
Posts: 38
Joined: Fri Jan 20, 2012 11:11 am

Re: User Profile with your login system.

Post by hys »

i have a problem now :s i deleted all my mysql and can't do the same as i had done :(
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: User Profile with your login system.

Post by Temor »

hys wrote: can't do the same as i had done :(
Why is that?
hys
Posts: 38
Joined: Fri Jan 20, 2012 11:11 am

Re: User Profile with your login system.

Post by hys »

i found out :D thanks anyway :d
Post Reply