Jump to content

Recommended Posts

I'm trying to separate some users (with admin rights) from others, so that they can view and enter some data that will be hidden from others in many consequent windows. My login page goes like this:

if (isset($_POST['Submit']))
{
$username = $_POST['username'];
$password = $_POST['password'];

$result = mysql_query("Select * From admin where username='$username'",$link);
if(mysql_num_rows($result)>0)
{
$row = mysql_fetch_array($result, MYSQL_BOTH);
if($password == $row["password"])
{
$_SESSION['adminok'] = "ok";
$_SESSION['username'] = "username";
$_SESSION['password'] = "password";
header("Location: admin.php");
}
else {$msg = "Password incorrect";}
}
else {$msg = "Username incorrect";}
}
?>

There's a row in the SQL table (admin_rights) that's either 0 or 1 (true/false). how can I pass this variable on to another php page to filter out some rows from other SQL tables, depending on this variable? I reckon it should go something like this:

$clientsresult = mysql_query("Select * from clients",$link);
$numcli = mysql_num_rows($clientsresult);
$nc = 0;
while($clients = mysql_fetch_array($clientsresult, MYSQL_BOTH)){
[b]if ($isadmin) {[/b]
$nc++;
$client[$clients['client_ID']] = $clients['name'];
}
}

Well, this seems simple, but how shall I get the [b]$isadmin[/b] from login page? This is also simple I know :) but I'm having awsome trouble. Help please! Thanks.
Cant you just add a session in the login page? Or am i misreading too?

[code]if (isset($_POST['Submit']))
{
$username = $_POST['username'];
$password = $_POST['password'];

$result = mysql_query("Select * From admin where username='$username'",$link);
if(mysql_num_rows($result)>0)
{
$row = mysql_fetch_array($result, MYSQL_BOTH);
if($password == $row["password"])
{
$_SESSION['isadmin'] = "1"; // 1 = yes, 0 = no
$_SESSION['adminok'] = "ok";
$_SESSION['username'] = "username";
$_SESSION['password'] = "password";
header("Location: admin.php");
}
else {$msg = "Password incorrect";}
}
else {$msg = "Username incorrect";}
}
?>[/code]

then in the other page

[code]$clientsresult = mysql_query("Select * from clients",$link);
$numcli = mysql_num_rows($clientsresult);
$nc = 0;
while($clients = mysql_fetch_array($clientsresult, MYSQL_BOTH)){
if ($_SESSION['isadmin'] == "1") {
$nc++;
$client[$clients['client_ID']] = $clients['name'];
}
}[/code]

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.