this is some of my script so far:
$check = ("SELECT username FROM users WHERE username = '$us3r'");
$check2 = ("SELECT password FROM users WHERE username = '$us3r'");
$check3 = ("SELECT userID FROM users WHERE username = '$us3r'");
$check4 = ("SELECT userrole FROM users WHERE username = '$us3r'");
//Role
$role = mysql_query($check4);
$arr5 = mysql_fetch_row($role);
$roles = ($arr5[0]);
echo $roles;
if($roles = 1) {
//Username
$results3 = mysql_query($check);
$arr2 = mysql_fetch_row($results3);
$results4 = ($arr2[0]);
//Password
$results5 = mysql_query($check2);
$arr3 = mysql_fetch_row($results5);
$results6 = ($arr3[0]);
//UID
$id1 = mysql_query($check3);
$arr4 = mysql_fetch_row($id1);
$id = ($arr4[0]);
echo 1;
}
else if($roles = 2) {
//Username
$mresults3 = mysql_query($check);
$marr2 = mysql_fetch_row($mresults3);
$mresults4 = ($marr2[0]);
//Password
$mresults5 = mysql_query($check2);
$marr3 = mysql_fetch_row($mresults5);
$mresults6 = ($arr3[0]);
//UID
$mid1 = mysql_query($check3);
$marr4 = mysql_fetch_row($mid1);
$mid = ($marr4[0]);
echo 2;
};
However there is something wrong with my if / else if for some reason the echo shows 21 when I use a user with a userrole of 2, I want it to be either 11 or 22 :/
You need to use
==for comparison instead of=:Change
to
and
to
If you use assignment (
=) instead of comparison (==) it will not only evaluate to true, but it also will change the variable.