dimiorla Posted May 2, 2009 Share Posted May 2, 2009 Hey everyone, i would like to get other echo depending the user role bat my code does not work (no surprise their). Any ideas Thanks in advance Dimi. $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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/156507-other-echo-depending-the-user-role/ Share on other sites More sharing options...
ignace Posted May 2, 2009 Share Posted May 2, 2009 <?php $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 (!sizeof($result)) { $output .= '<loginsuccess>no</loginsuccess>'; } else if ($role === 'user') { $output .='<loginsuccess>user</loginsuccess>'; } else if($role === 'admin') { $output .= '<loginsuccess>admin</loginsuccess>'; } echo $output; ?> Quote Link to comment https://forums.phpfreaks.com/topic/156507-other-echo-depending-the-user-role/#findComment-824139 Share on other sites More sharing options...
dimiorla Posted May 3, 2009 Author Share Posted May 3, 2009 Sorry, My mistake, my code does not work because it expects the role to be provided by the application . $role = mysql_real_escape_string($_POST['role']); Bat what I would like is to get it by the user array in mysql I have to do my homework better :-\ Quote Link to comment https://forums.phpfreaks.com/topic/156507-other-echo-depending-the-user-role/#findComment-824574 Share on other sites More sharing options...
Ken2k7 Posted May 3, 2009 Share Posted May 3, 2009 I have to do my homework better :-\ Some things are better left unsaid. Quote Link to comment https://forums.phpfreaks.com/topic/156507-other-echo-depending-the-user-role/#findComment-824581 Share on other sites More sharing options...
dimiorla Posted May 3, 2009 Author Share Posted May 3, 2009 Oh men i can’t find an example online on how to get the user role from the db. And the thinks I have tried don’t work. ignace: thanks for your code, but how should i change the following line? $role = mysql_real_escape_string($_POST['role']); Quote Link to comment https://forums.phpfreaks.com/topic/156507-other-echo-depending-the-user-role/#findComment-824804 Share on other sites More sharing options...
ignace Posted May 3, 2009 Share Posted May 3, 2009 I have actually no idea to what role you are referring are you using an access control list? and have you got a roles table in your database? <?php $username = mysql_real_escape_string($_POST["username"]); $password = mysql_real_escape_string($_POST["password"]); $query = "SELECT roles.role FROM roles, users WHERE roles.id = users.roles_id AND (username = '$username' AND password = '$password')"; $result = mysql_query($query) or exit(mysql_error()); list($role) = mysql_fetch_array($result, MYSQL_FETCH_NUM); .. ?> Quote Link to comment https://forums.phpfreaks.com/topic/156507-other-echo-depending-the-user-role/#findComment-824850 Share on other sites More sharing options...
dimiorla Posted May 3, 2009 Author Share Posted May 3, 2009 Thanks for you reaction. my table has the following structure TABLE `users`(`id`, `username`, `password`, `role`) VALUES (0, 'Employee2', '123', 'user'), (1, 'Manager', '456', 'admin'), (2, 'Employee1', '789', 'user'); if the password and username are corect then depending the role of the user (admin or normaal user) my application (flex) wil show an other state(page) Quote Link to comment https://forums.phpfreaks.com/topic/156507-other-echo-depending-the-user-role/#findComment-824865 Share on other sites More sharing options...
dimiorla Posted May 3, 2009 Author Share Posted May 3, 2009 p.s. How can i echo the user name. $output .= '<user>$username</user>'; doesn't work Quote Link to comment https://forums.phpfreaks.com/topic/156507-other-echo-depending-the-user-role/#findComment-824894 Share on other sites More sharing options...
Ken2k7 Posted May 3, 2009 Share Posted May 3, 2009 p.s. How can i echo the user name. $output .= '<user>$username</user>'; doesn't work Can you post your updated code? Quote Link to comment https://forums.phpfreaks.com/topic/156507-other-echo-depending-the-user-role/#findComment-824956 Share on other sites More sharing options...
mattal999 Posted May 3, 2009 Share Posted May 3, 2009 <?php $username = mysql_real_escape_string($_POST["username"]); $password = mysql_real_escape_string($_POST["password"]); $query = "SELECT * FROM users WHERE username = '$username' AND password = '$password'" ; $result = mysql_fetch_array(mysql_query($query)); if (!sizeof($result)) { $output .= '<loginsuccess>no</loginsuccess>'; } else if ($result['role'] === 'user') { $output .='<loginsuccess>user</loginsuccess>'; } else if($result['role'] === 'admin') { $output .= '<loginsuccess>admin</loginsuccess>'; } echo $output; // Echoing usernames: echo $username; //or echo $_POST['username']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/156507-other-echo-depending-the-user-role/#findComment-824958 Share on other sites More sharing options...
dimiorla Posted May 3, 2009 Author Share Posted May 3, 2009 mattal999 how can i get the role from the db (see table structure) to be equal to $role. otherwise this doesn't work else if ($result['role'] === 'user') { $output .='<loginsuccess>user</loginsuccess>'; Thanks for you help Thanks for you reaction. my table has the following structure TABLE `users`(`id`, `username`, `password`, `role`) VALUES (0, 'Employee2', '123', 'user'), (1, 'Manager', '456', 'admin'), (2, 'Employee1', '789', 'user'); if the password and username are corect then depending the role of the user (admin or normaal user) my application (flex) wil show an other state(page) Quote Link to comment https://forums.phpfreaks.com/topic/156507-other-echo-depending-the-user-role/#findComment-824968 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.