Jump to content

PHP/MySQL - Show page based on user level?


silver9990

Recommended Posts

Here's my problem, I've been trying to get this to work for 8 hours:

 


//connection info and query info

if ($row["group"] == "1") {

show

} else {

don't show

}

 

I can't remember the exact codes I've tried but none of them have worked, I always end up with this:

 

Warning: mysql_num_rows(): supplied argument is not a valid mysql result resource in file.php on line x

 

Any help would be appreciated.

Link to comment
Share on other sites

Use this:

 

$q = mysql_query("SELECT * FROM `table` WHERE group = '1'");
$r = mysql_fetch_array($q);
if($r['group'] == COOKIE/SESSION) {
   echo "Has access to the page";
} else {
   echo "Sorry, you do not have access to this page";
}

 

Change the COOKIE/SESSION to whatever you use to store the users level who is browsing the page.

Link to comment
Share on other sites

Thanks for the replies but both give me errors.

 

I've added the correct info for both and this is what shows up:

 

"localhost","dbuser","pass":

Parse error: syntax error, unexpected ',' in test.php on line 3

 

$r = mysql_fetch_array($q);:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in test2.php on line 9

Link to comment
Share on other sites

Here:

 

sql.inc.php:

$db_user = ""; // Username
$db_pass = ""; // Password
$db_database = ""; // Database Name
$db_host = ""; // Server Hostname

// DO NOT EDIT ANYTHING AFTER THIS LINE!
$db_connect = @mysql_connect ($db_host, $db_user, $db_pass);
$db_select = @mysql_select_db ($db_database);

 

page.php:

include("sql.inc.php");

$q = mysql_query("SELECT * FROM `table` WHERE group = '1'") or die (mysql_error());
$r = mysql_fetch_array($q);

if($r['group'] == COOKIE/SESSION) {
// has access
} else {
// Doesnt have access
}

 

Make sure you change the db info and the sql info to your server info.

Link to comment
Share on other sites

why don't you do it like this?

 

<?php

// I'm presuming you have a session login, so do this...

$sql = mysql_query("SELECT * FROM `member_table` WHERE `username_column` = '". $_SESSION['session'] ."'");

while($row = mysql_fetch_assoc($sql)){

if($row['group'] != 1){

// Whatever error screen you want to show if the user isn't authorized
exit();

}else{

// The page

}
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.