SkyRanger Posted March 17, 2009 Share Posted March 17, 2009 I am trying to figure out how to pull multiple info from a database to show a page or not.... for example: if $row['userip] = $_SERVER['REMOTE_ADDR'] and $banned = 0 then show page else if $row['userip] = $_SERVER['REMOTE_ADDR'] and $banned = 1 then don't show the page. Any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/149765-solved-trying-to-figure-out-how-to-do/ Share on other sites More sharing options...
Zane Posted March 17, 2009 Share Posted March 17, 2009 if($row['userip] = $_SERVER['REMOTE_ADDR']) { if(!$banned) { echo "The page is shown"; } } Quote Link to comment https://forums.phpfreaks.com/topic/149765-solved-trying-to-figure-out-how-to-do/#findComment-786439 Share on other sites More sharing options...
SkyRanger Posted March 17, 2009 Author Share Posted March 17, 2009 Ok, this is what I have so far: mysql_connect("localhost", "dbuser", "dbpass") or die(mysql_error()); mysql_select_db("dbname") or die(mysql_error()); $result = mysql_query("SELECT * FROM table") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { if($row['userip'] = $_SERVER['REMOTE_ADDR']) { if(!$ban) { echo "show the webpage"; } } } [code] Tried banning my own IP but still showing page. Quote Link to comment https://forums.phpfreaks.com/topic/149765-solved-trying-to-figure-out-how-to-do/#findComment-786442 Share on other sites More sharing options...
Zane Posted March 17, 2009 Share Posted March 17, 2009 going out on a limb here but try using if(!$row['ban']) instead of if(!$ban) Quote Link to comment https://forums.phpfreaks.com/topic/149765-solved-trying-to-figure-out-how-to-do/#findComment-786451 Share on other sites More sharing options...
SkyRanger Posted March 17, 2009 Author Share Posted March 17, 2009 No, still showing page. What is making it read the $ban code if it is 0 or 1. 0 = not banned and 1 is banned? Quote Link to comment https://forums.phpfreaks.com/topic/149765-solved-trying-to-figure-out-how-to-do/#findComment-786467 Share on other sites More sharing options...
Silverado_NL Posted March 17, 2009 Share Posted March 17, 2009 where is the info if the user is banned or not? if its in the database and u select it aswell (this example show's if there is a column in the table called 'ban') try this i am using a 0 for false and a 1 for true while($row = mysql_fetch_array( $result )) { if($row['userip'] = $_SERVER['REMOTE_ADDR']) { if($row['ban'] == 0) { //make sure the ROW array contains the key 'ban' with a value of 1 to ban the person (cause if its a 0 it will just show it) echo "show the webpage"; } } } i gave it a try without database and while loop but just make a array like this $row = array('userip' => 'localhost','ban' => '1'); and it worked Quote Link to comment https://forums.phpfreaks.com/topic/149765-solved-trying-to-figure-out-how-to-do/#findComment-786479 Share on other sites More sharing options...
SkyRanger Posted March 17, 2009 Author Share Posted March 17, 2009 Thanks for you help guys, works perfectly. Just need to tweak it some to show banned users a page saying they are banned. Quote Link to comment https://forums.phpfreaks.com/topic/149765-solved-trying-to-figure-out-how-to-do/#findComment-786834 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.