
Originally Posted by
keyboard1333
PHP Code:
$sql = mysql_query ("SELECT * FROM users") or die(mysql_error());;
$gordon = mysql_fetch_array ($sql);
if ($row['level']= "9"){
echo "Admin"}
( ! ) Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in C:\Documents and Settings\Owner\Desktop\canberra amatuer productions\www\Canberra Amatuer Productions\echo time.php on line 103
In addition, you have an extra semicolon after your first line above. It should look like this:
PHP Code:
$sql = mysql_query("SELECT * FROM users") or die(mysql_error());
$gordon = mysql_fetch_array($sql);
if ($row['level'] == "9"){ echo "Admin"; }
If you're still getting an error, then it is occurring somewhere else.
Remember that the error is reported at the line where PHP can no longer recover; which is not necessarily (in fact, usually isn't) where the actual mistake is.
However, you're still only checking the first row. If the first user in your DB is an admin, this will always print "Admin"; if not, then it will never do anything.
The query is also very heavy (you're retrieving all columns from all records but only using one column from one record). If you get hundreds of users (or thousands) and you're doing this check every time a certain page (or any page) is loaded, it will be slow. You should only select what you need in your query. You could even do the entire check via mysql, and not have to process any of it in php.
If you want to know if a particular user is an admin, try something more like this:
PHP Code:
$userid = ''; // user id to check (whatever unique column you use)
$SQL = "SELECT `id` FROM `users` WHERE `id`='$userid' AND `level`='9' LIMIT 1";
// this way, you only get a match if the user *also* has level=9.
// if you get no results, then you know that the user is _not_ level=9.
if( mysql_num_rows( mysql_query($SQL) ) === 1 ){ print "User $userid is an Admin"; }
else{ print "User $userid is a loser."; }
Bookmarks