Re: User Profile with your login system.
Posted: Sun Feb 05, 2012 6:41 pm
waiting for jacek to look at code
The non-existent community
https://betterphp.co.uk/board/
It all looks very fine and neat except for this little bithys wrote:waiting for jacek to look at code
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.
$sql = 'SELECT `user_id` FROM `users` WHERE `user_name` = '{$username}'';
$sql = 'SELECT `user_name` FROM `users` WHERE `user_id` = '{$username}'';
$sql = "SELECT `user_id` FROM `users` WHERE `user_name` = '{$username}'";
Why is that?hys wrote: can't do the same as i had done