if statement / mysql query
Posted: Thu Feb 11, 2010 10:50 am
The following code is testing my patience because I know I should know what is wrong and I can't get it working. This is just a simple exercise for me to keep my php skills up to scratch whilst I hack and slash other peoples sites and fix them / do text changes etc.
Whats happening is I'm sent to the rediect every time. I think that my $userlevel isn't being set to admin or member... If I have ($userlevel = "admin") with one equals not too that information is echoed, even if I have logged into the user with 'member' status. If i set if ($userlevel == "admin") with two equals and if ($userlevel = "member") has one equals I go to member. Hence I think something is wrong with my query.
I know its likely going to be obivous but I haven't done any 'start from scratch' php coding in a long while ^_^'
Whats happening is I'm sent to the rediect every time. I think that my $userlevel isn't being set to admin or member... If I have ($userlevel = "admin") with one equals not too that information is echoed, even if I have logged into the user with 'member' status. If i set if ($userlevel == "admin") with two equals and if ($userlevel = "member") has one equals I go to member. Hence I think something is wrong with my query.
Code: Select all
session_start();
include("validate.php");
include("connection.php");
if ($_SESSION['id'] != '' or validatelogin($_POST['txtid'],$_POST['txtpwd']) == true){
$_SESSION['id'] = $_POST['txtid'];
$sql = "Select userlevel from userdetails where username='" . $_SESSION['id'] . "'";
$userlevel = mysql_query($sql, $conn);
if ($userlevel == "admin")
{
echo "You are now logged in as " . $_SESSION['id'] . " your level is Administrator";
echo "<br><a href='newpage.php'>User Control</a>";
echo "<br><a href='adminindex.php'>Enter Administration Area</a>";
}
elseif ($userlevel == "member")
{
echo "You are now logged in as " . $_SESSION['id'] . " your level is Member";
echo "<br><a href='newpage.php'>User Control</a>";
}
else
{
echo "You have posted incorrect log in data you will automatically be redirected";
echo "<head><meta HTTP-EQUIV='REFRESH' content='10; url=home.html'></head>";
}
}