Jump to content

Archived

This topic is now archived and is closed to further replies.

BillyBoB

help with coding

Recommended Posts

ok im having a weird error with a code that somone gave me
and wanted to see if somone could help

heres 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]

Share this post


Link to post
Share on other sites
um heres a question do u think it wont work if there isnt ne ips in there ?

Share this post


Link to post
Share on other sites
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();

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

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.