Jump to content

other echo depending the user role


dimiorla

Recommended Posts

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
?>

Link to comment
https://forums.phpfreaks.com/topic/156507-other-echo-depending-the-user-role/
Share on other sites

<?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;
?>

Sorry,

My mistake, my code does not work because it expects the role to be provided by the application :o.

 

$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 :-\

 

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);

..
?>

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)

 

<?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'];

?>

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)

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.