Jump to content

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

 

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

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)

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.