Page 3 of 3

Re: User Profile with your login system.

Posted: Sun Feb 05, 2012 6:41 pm
by hys
waiting for jacek to look at code :)

Re: User Profile with your login system.

Posted: Sun Feb 05, 2012 11:49 pm
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}'';

Re: User Profile with your login system.

Posted: Mon Feb 06, 2012 8:23 am
by hys
Can it be this?
$sql = 'SELECT `user_name` FROM `users` WHERE `user_id` = '{$username}'';

Re: User Profile with your login system.

Posted: Mon Feb 06, 2012 9:56 pm
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}'";

Re: User Profile with your login system.

Posted: Mon Feb 06, 2012 10:33 pm
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

Re: User Profile with your login system.

Posted: Wed Feb 08, 2012 4:15 pm
by jacek
Quite a lot ;)

Re: User Profile with your login system.

Posted: Thu Apr 26, 2012 1:12 pm
by hys
i have a problem now :s i deleted all my mysql and can't do the same as i had done :(

Re: User Profile with your login system.

Posted: Fri Apr 27, 2012 12:39 pm
by Temor
hys wrote: can't do the same as i had done :(
Why is that?

Re: User Profile with your login system.

Posted: Sun May 06, 2012 6:45 pm
by hys
i found out :D thanks anyway :d