Hi everyone
I am using this login code to play around and try to learn php in a bit more detail.
I am getting the following error;
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Web\LVA\root2\includes\functions.php on line 6
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Web\LVA\root2\includes\functions.php on line 15
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Web\LVA\root2\includes\functions.php on line 16
Notice: Undefined variable: memid in C:\Web\LVA\root2\includes\functions.php on line 23
here is the code:
function member_login($username, $password)
{
// Try and get the salt from the database using the username
$query = "select salt from members where username='$username' limit 1"; //changed user to member
$result = mysql_query($query);
$member = mysql_fetch_array($result); //changed user to member
// Using the salt, encrypt the given password to see if it
// matches the one in the database
$encrypted_pass = md5(md5($password).$member['salt']);
// Try and get the user using the username & encrypted pass
$query = "select memid, username from member where username='$username' and pass='$encrypted_pass'";
$result = mysql_query($query);
$member = mysql_fetch_array($result);
$numrows = mysql_num_rows($result);
// Now encrypt the data to be stored in the session
$encrypted_id = md5($member['memid']);
$encrypted_name = md5($member['username']);
// Store the data in the session
$_SESSION['userid'] = $memid; //keep this as userid for session referances throughout code
$_SESSION['username'] = $username;
$_SESSION['encrypted_id'] = $encrypted_id;
$_SESSION['encrypted_name'] = $encrypted_name;
if ($numrows == 1)
{
return 'Correct';
}
else
{
return false;
}
}
If anyone can help with why this error is coming up it would really help. The username and password i am using are valid and exist in the members table.