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
INSERT for date range
Hi all
I have the following table
Code: [Select] `date` date
`day` int(2)
`
Problem with array max size.
Hi to everyone,
I've got a homework about filling a bidimensional array un spiral shape, I alre
Posting Serialized Data Not Working
I am trying to send an object from one PHP file to another using POST. I serialize the object and th
error checking breaking my code
Hi there, OK first of all, big apologies for what I assume is really fundamental errors in the struc
This must be easy , pulling the last record of the day, every day, from a txt
I have a txt file logging weather data every minutes (so 1 record per minute). I want to extract the
PHP Blog help
Need help with posting comments in a word press blog? I have a comments page where the comments are
Logic question
im wondering what's the best method to do the above list:
it is for alliance @ MMORPG game
Multidimensional $_POST
Hello
How to get a single array from array of array (2 - dimension).
For example I have a
Not "Just Another" MMORPG - text based.
Hello,
I've been learning MySQL and PHP for the last 2-3 years.
Though, I've had long paus
user data not transferring to new page
I'm a PHP learner. After an index.php page, the user goes to a login.php page. Both pages seem to