PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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.
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>";
}
}
I know its likely going to be obivous but I haven't done any 'start from scratch' php coding in a long while ^_^'
Maybe you should do some basic troubleshooting, like echo $userlevel; etc...
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
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>";
}
}
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>";
}
}