Well, being a learning experience, I'd love to understand the code perfectly right off the bat, but I'd guess its more of the syntax. I understand how to query, and I understand the code used to query, but what you said
For only the user that is logged in, this should be changed to
Code:
SELECT * FROM users WHERE user_id='user_id_stored_in_a_session'
The only problem with that, I do not see the term 'stored_in_a_session' in php.net, google, or anything.
This is more along the lines of what I have where the login creates the session
function user_login($username, $password)
{
// Try and get the salt from the database using the username
$query = "select salt from user where username='$username' limit 1";
$result = mysql_query($query);
if (mysql_num_rows($result) > 0)
{
// Get the user
$user = mysql_fetch_array($result);
// Using the salt, encrypt the given password to see if it
// matches the one in the database
$encrypted_pass = md5(md5($password).$user['salt']);
// Try and get the user using the username & encrypted pass
$query = "select userid, username from user where username='$username' and password='$encrypted_pass'";
$result = mysql_query($query);
if (mysql_num_rows($result) > 0)
{
$user = mysql_fetch_array($result);
// Now encrypt the data to be stored in the session
$encrypted_id = md5($user['userid']);
$encrypted_name = md5($user['username']);
// Store the data in the session
$_SESSION['userid'] = $userid;
$_SESSION['username'] = $username;
$_SESSION['encrypted_id'] = $encrypted_id;
$_SESSION['encrypted_name'] = $encrypted_name;
// Return ok code
return 'Correct';
}
else
{
return 'Invalid Password';
}
}
else
{
return 'Invalid Username';
}
}
I understand the salt as the encryption, I understand how it works to match the username and encrypted password. What it comes down to is, I am not sure how to call on the session userid to have it display only those results. I don't know if i call on the userid or encrypted userid, or if I have to unencrypt the session data to call against mysql, and the implications of doing any of those choices.