Redirecting Admin
Posted on
16th Feb 2014 07:03 pm by
admin
In my members table, I have a field called "perm" and it's set to zero for all members. However, I have two administrators, and theirs are set to 1.
I want my members page that shows up on login to redirect admins if their "perm" number is set to 1
Right now it's not having any errors, but it's not redirecting the admins.
Thank you!
Full code:
Code: <?php
// Connects to your Database
...
//checks cookies to make sure they are logged in
if(isset($_COOKIE['ID_staples_clubs']))
{
$username = $_COOKIE['ID_staples_clubs'];
$pass = $_COOKIE['Key_staples_clubs'];
$check = mysql_query("SELECT * FROM members WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
//if the cookie has the wrong password, they are taken to the login page
if ($pass != $info['password'])
{ header("Location: login.php");
}
//otherwise they are shown the member area
else
{
$query = "SELECT clubs.*, members.* FROM clubs LEFT JOIN members ON members.club = clubs.id WHERE members.username = '{$_COOKIE['ID_staples_clubs']}'";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
//admin
if ($row['perm'] == 1) {
header("Location: admin.php");
}
//member
else {
echo "$row[name] <br />";
echo "Welcome, ";
echo "$row[adv] <br />";
echo "<a href=edititem.php?id=$row[club]>Edit Club</a>";
echo "<br />";
echo "<a href=changepass.php>Change password</a><br />";
echo "<a href=logout.php>Logout</a>";
}
}
}
}
}
else
//if the cookie does not exist, they are taken to the login screen
{
header("Location: login.php");
}
?>
Troublesome part:
Code: while ($row = mysql_fetch_array($result)) {
//admin
if ($row['perm'] == 1) {
header("Location: admin.php");
}
//member
else {
echo "$row[name] <br />";
echo "Welcome, ";
echo "$row[adv] <br />";
echo "<a href=edititem.php?id=$row[club]>Edit Club</a>";
echo "<br />";
echo "<a href=changepass.php>Change password</a><br />";
echo "<a href=logout.php>Logout</a>";
}
No comments posted yet
Your Answer:
Login to answer
225
16
Other forums
regex for quoted text within a string
I am still getting the hang of regex expressions, but I cant seem to figure out how I would escape q
Beginner PHP code help
Hi I'm new to php but if someone could please read the question below and help it would be great.
mysqli_fetch_assoc returns multiple arrays, how to return a single array
Hello, I am using mysqli_fetch_assoc which is returning multiple rows, so it looks like:
Code
Inserting 100x and 100y coordinates in mysql table - easy
Is there a way to insert this data into a mysql table named 'map' with the fields: 'x int 3' , 'y in
How to assign a textbox value to PHP variable??
Hi ! Can any one help me out as quickly as possible. As I m new to PHP.
Plz tell me how to assign
php mysql script to find record
Hi,
Currently I have a simple table with 4 columns. A, B, C, D
If I want to find all
need help in php variable
i have a php variable on one page
Code: [Select]$lastId = mysql_insert_id($db);
echo $lastId;<
Header redirect
Hello ive got a problem ive got form with its action set to itself.
Code: <form id="f
compile php5 with DOM
Hi,
I can't manage to compile php 5.3.0 from source on Windows to include DOM,
in spite of
I have a parse error in this query help..
Code: $query1="INSERT INTO `rating` (`item_name`, `rating`, `ip_address`, `date_rated`) VALUES