BillyBoB Posted July 16, 2006 Share Posted July 16, 2006 ok im having a weird error with a code that somone gave meand wanted to see if somone could helpheres the code:[code]<?php ob_start(); $conn = mysql_connect("localhost","user","pass"); mysql_select_db(database) or die(mysql_error()); $logged = MYSQL_QUERY("SELECT * from users WHERE id='$_COOKIE[id]' AND password = '$_COOKIE[pass]'"); $logged = mysql_fetch_array($logged); $fffquery = mysql_query("SELECT * FROM banned "); $bannedips = mysql_fetch_array($fffquery); if(in_array($_SERVER['REMOTE_ADDR'], $bannedips)) { // this is line 9 print("You have been banned from this website and are unable to view it."); exit(); }?> [/code]and heres the error:[code]Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/dreamsh/public_html/config.php on line 9[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14725-help-with-coding/ Share on other sites More sharing options...
BillyBoB Posted July 16, 2006 Author Share Posted July 16, 2006 um heres a question do u think it wont work if there isnt ne ips in there ? Quote Link to comment https://forums.phpfreaks.com/topic/14725-help-with-coding/#findComment-58743 Share on other sites More sharing options...
hvle Posted July 16, 2006 Share Posted July 16, 2006 yes, that's right, if there isn't any ip in there, it'll give that error.to fix the error, at least declare $bannedips an array:$bannedips = array(); Quote Link to comment https://forums.phpfreaks.com/topic/14725-help-with-coding/#findComment-58744 Share on other sites More sharing options...
akitchin Posted July 16, 2006 Share Posted July 16, 2006 it's because in_array() expects an actual array for its second parameter. what the error means is that your $bannedips isn't an actual array. there are a few possible reasons for it not being an array:1. your query is failing. add an "or die(mysql_error())" clause to the end of your mysql_query() statement on line 7. i have a feeling the extra space at the end of the query will throw an error.2. the query isn't returning any rows, in which case $bannedips will be empty.regardless, i don't think this script will do what you want. you have to go through each row in the `banned` table and assign the IP from that row to an array, like so:[code]<?php$bannedips = array();while ($row = mysql_fetch_array($fffquery)){ $bannedips[] = $row['ip_column_name'];}?>[/code]this way, $bannedips is an array whether it returns any rows or not and it should avoid giving you an error for using in_array(). these lines can replace the line "$bannedips = mysql_fetch_array($fffquery);". replace "ip_column_name" with whatever the name of the field you're storing the IP in is. Quote Link to comment https://forums.phpfreaks.com/topic/14725-help-with-coding/#findComment-58746 Share on other sites More sharing options...
BillyBoB Posted July 16, 2006 Author Share Posted July 16, 2006 ok thanks Quote Link to comment https://forums.phpfreaks.com/topic/14725-help-with-coding/#findComment-58747 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.