PDA

View Full Version : log in to other states depending the user role


dimiorla
04-30-2009, 02:12 PM
Hey everyone,
i would like log in to other states depending the user role bat my code does not work (no surprise their).
Any ideas
Thanks in advance Dimi.


private function checkLogin(evt:ResultEvent):void
{
if(evt.result.loginsuccess == "admin")
{
currentState = "admin";
}
if(evt.result.loginsuccess == "user")
{
currentState = "user";
}
if(evt.result.loginsuccess == "no")
{
mx.controls.Alert.show('Invalid username/password');
}
}


$username = mysql_real_escape_string($_POST["username"]);
$password = mysql_real_escape_string($_POST["password"]);
$role = mysql_real_escape_string($_POST['role']);
$query = "SELECT * FROM users WHERE username = '$username' AND password = '$password'" ;
$result = mysql_fetch_array(mysql_query($query));
if (!$result)
{
$output .= "<loginsuccess>no</loginsuccess>";
}
elseif (!$result == "yes" || $role == "user" )
{
$output .="<loginsuccess>user</loginsuccess>";
}
elseif(!$result == "yes" || $role == "admin" )
{
$output .= "<loginsuccess>admin</loginsuccess>";
}
echo $output
?>

mattb
05-26-2009, 06:00 PM
In your PHP code, $result is an array containing the column values returned by your SQL query, yet you're treating it as a string.

If you simply want to know if the query yielded a result, you could check the number of rows returned by the query and accept/deny on that basis.