mySQL + php problem
Posted: Tue Sep 23, 2003 2:14 pm
hi all
i am trying to write this small piece of php that checks for a field called "admin" in a table called "users", and sees if that field is a 1 or a 0, and give an outcome based on that query.
this is what i have so far:
my problem is, even though i know there IS a username field called "freakishkid", whenever i am logged in with that user, the script returns the second else ("No user freakishkid found"). could anyone assist me with this?
i guess that it is something simple, but i am new to php so cannot see it.
thanks in advance,
fk
i am trying to write this small piece of php that checks for a field called "admin" in a table called "users", and sees if that field is a 1 or a 0, and give an outcome based on that query.
this is what i have so far:
Code: Select all
$username = $_SESSION['username'];
$sqlQuery = "select admin from users where username = '$username'";
$result = mysql_query($sqlQuery);
if($result == 1)
{
// The query is ok, now check for admin
$row = mysql_fetch_row($result);
$admin = $row[0];
if($admin != 1)
{
// User is NO ADMIN
echo '<a href="apply.php">apply</a><br>';
} else {
// User is ADMIN
echo '<a href="template.php">template</a><br>';
}
} else {
echo "No user $username found";
}
?>i guess that it is something simple, but i am new to php so cannot see it.
thanks in advance,
fk