authorizing through levels! check my code!!
| From: | Thomas Edison Jr. | Date: | Sun, 25 Jun 2000 15:18:45 +0000 |
| Subject: | authorizing through levels! check my code!! | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-2989@lists.php.net to get a copy of this message | ||
I have a database with employee information. Each
employee is assigned a level like 1, 2, 3 etc. There
is a page which displays employee information from the
database. There are restrictions for every employee to
view database information according to the level he
possess. For example, an employee with level "1" may
view ALL the records, whereas an employee with level
"2" can view only few records.
I tried a code to check only for level "1" right now,
and in this case all records should be printed. All
records ARE being printed but so is the line below
"Sorry, you are not authorised to view project
information."!! WHY is this line also being printed??
What is wrong???
This line should be printed only when he feeds in a
wrong user & password.
the code is following with $u & $p being user &
password of the employee entering this page being sent
from the form on the previous HTML file.
<?
$db = mysql_connect("localhost", "root");
mysql_select_db("try",$db);
$result = mysql_query("SELECT * FROM motorola",$db);
if ($myrow = mysql_fetch_array($result)) {
do {
if ($u == $myrow["user"] && $p == $myrow["pass"]) {
//authorizing for levels
if ($myrow["level"] == "1") {
$result = mysql_query("SELECT * FROM motorola",$db);
if ($myrow = mysql_fetch_array($result)) {
do {
printf("name : $myrow[name], email : $myrow[email]
\n");
} while ($myrow = mysql_fetch_array($result));
}
}
//ending
break;
}
} while ($myrow = mysql_fetch_array($result));
if ($u != $myrow["user"] && $p != $myrow["pass"]) {
echo "Sorry, you are not authorised to view project
information.";
}
else {
echo "Sorry, no records matching your criteria were
found in our database.";
}
?>
Please help me someone.
Regards,
T. Edison jr.
=====
Rahul S. Johari (Director)
******************************************
Abraxas Technologies Inc.
Homepage : http://www.abraxastech.com
Email : abraxastech@yahoo.com
Tel : 91-4546512/4522124
*******************************************
__________________________________________________
Do You Yahoo!?
Get Yahoo! Mail - Free email you can access from anywhere!
http://mail.yahoo.com/