silver9990 Posted October 27, 2007 Share Posted October 27, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/74999-phpmysql-show-page-based-on-user-level/ Share on other sites More sharing options...
darkfreaks Posted October 27, 2007 Share Posted October 27, 2007 <?php $link=("localhost","dbuser","pass"); mysql_select_db("database",$link); $row=mysql_num_rows($result); if ($row["group"] == "1") { ///show } else { ///don't show }?> Quote Link to comment https://forums.phpfreaks.com/topic/74999-phpmysql-show-page-based-on-user-level/#findComment-379282 Share on other sites More sharing options...
unidox Posted October 27, 2007 Share Posted October 27, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/74999-phpmysql-show-page-based-on-user-level/#findComment-379294 Share on other sites More sharing options...
silver9990 Posted October 27, 2007 Author Share Posted October 27, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/74999-phpmysql-show-page-based-on-user-level/#findComment-379314 Share on other sites More sharing options...
darkfreaks Posted October 27, 2007 Share Posted October 27, 2007 <?php $link=("localhost","dbuser","pass"); mysql_select_db("database",$link); $result = mysql_query("SELECT * FROM table1", $link); $row=mysql_num_rows($result); if ($row["group"] == "1") { ///show } else { ///don't show }?> Quote Link to comment https://forums.phpfreaks.com/topic/74999-phpmysql-show-page-based-on-user-level/#findComment-379317 Share on other sites More sharing options...
unidox Posted October 27, 2007 Share Posted October 27, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/74999-phpmysql-show-page-based-on-user-level/#findComment-379393 Share on other sites More sharing options...
silver9990 Posted October 28, 2007 Author Share Posted October 28, 2007 Still not working, if I set the users group to a value of 2 the user still has access. This can be closed, I'll try and come up with something else, thanks for the help anyways. Quote Link to comment https://forums.phpfreaks.com/topic/74999-phpmysql-show-page-based-on-user-level/#findComment-379687 Share on other sites More sharing options...
LemonInflux Posted October 28, 2007 Share Posted October 28, 2007 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 } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/74999-phpmysql-show-page-based-on-user-level/#findComment-379688 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.