Bman900 Posted May 15, 2009 Share Posted May 15, 2009 I want implement something where the persons IP is looked up in my database and if it is found display something and if it isn't display another thing. The only trouble I have is how would I check for the IP in my table (checkip)? Quote Link to comment https://forums.phpfreaks.com/topic/158266-if-ip-is-in-the-databse-do-this/ Share on other sites More sharing options...
.josh Posted May 15, 2009 Share Posted May 15, 2009 you would check it the same way as you check if anything else is in your table. select column from table where column = 'somevalue' ... if (mysql_num_rows > 0) { // something was returned, do something } edit: that's obviously pseudo-code. Quote Link to comment https://forums.phpfreaks.com/topic/158266-if-ip-is-in-the-databse-do-this/#findComment-834713 Share on other sites More sharing options...
Ken2k7 Posted May 15, 2009 Share Posted May 15, 2009 This is an alternative - SELECT COUNT(column) AS cnt FROM table WHERE column = 'somevalue'; ... if ($row['cnt'] > 0) { /* do something */ } Quote Link to comment https://forums.phpfreaks.com/topic/158266-if-ip-is-in-the-databse-do-this/#findComment-834759 Share on other sites More sharing options...
Bman900 Posted May 15, 2009 Author Share Posted May 15, 2009 Would this be correct? <?php $ipchecker = $_SERVER['REMOTE_ADDR']; mysql_query("select iptable from ipcheck where iptable = '$ipchecker'"); if (mysql_num_rows > 0) { ?> <form id="form1" method="post" action="redirect.php"> <textarea name="question" cols="52" rows="8"></textarea><br /> <input name="firstname" type="text" /><br /> <input name="email" type="text" /><br /> <input name="submit" type="submit" /> </form> <?php } else { ?> <script type="text/javascript" src="http://forms.aweber.com/form/40/1675361340.js"></script> <?php } ?> I added my IP manualy to test it out and it goes to the else statement no matter what. Quote Link to comment https://forums.phpfreaks.com/topic/158266-if-ip-is-in-the-databse-do-this/#findComment-834834 Share on other sites More sharing options...
.josh Posted May 15, 2009 Share Posted May 15, 2009 no...i told you, that was pseudo code. You need to assign the mysql_query to a variable and use that variable as argument in mysql_num_rows. mysql_query mysql_num_rows Quote Link to comment https://forums.phpfreaks.com/topic/158266-if-ip-is-in-the-databse-do-this/#findComment-834841 Share on other sites More sharing options...
Bman900 Posted May 15, 2009 Author Share Posted May 15, 2009 no...i told you, that was pseudo code. You need to assign the mysql_query to a variable and use that variable as argument in mysql_num_rows. mysql_query mysql_num_rows You mean like this: <?php $ipchecker = $_SERVER['REMOTE_ADDR']; $ipsql = mysql_query("select iptable from ipcheck where iptable = '$ipchecker'"); $row_number = mysql_num_rows($ipsql); if ($row_number > 0) { ?> <form id="form1" method="post" action="redirect.php"> <textarea name="question" cols="52" rows="8"></textarea><br /> <input name="firstname" type="text" /><br /> <input name="email" type="text" /><br /> <input name="submit" type="submit" /> </form> <?php } else { ?> <script type="text/javascript" src="http://forms.aweber.com/form/40/1675361340.js"></script> <?php } ?> That doesn't work either... Quote Link to comment https://forums.phpfreaks.com/topic/158266-if-ip-is-in-the-databse-do-this/#findComment-834848 Share on other sites More sharing options...
Ken2k7 Posted May 15, 2009 Share Posted May 15, 2009 So your SQL returns no results. I would check my SQL if I were you. Quote Link to comment https://forums.phpfreaks.com/topic/158266-if-ip-is-in-the-databse-do-this/#findComment-834849 Share on other sites More sharing options...
Bman900 Posted May 15, 2009 Author Share Posted May 15, 2009 So your SQL returns no results. I would check my SQL if I were you. THANK YOU! I don't know what I was thinking but my table was wrong. Quote Link to comment https://forums.phpfreaks.com/topic/158266-if-ip-is-in-the-databse-do-this/#findComment-834852 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.