Jump to content

help with coding


BillyBoB

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]
Link to comment
https://forums.phpfreaks.com/topic/14725-help-with-coding/
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.
Link to comment
https://forums.phpfreaks.com/topic/14725-help-with-coding/#findComment-58746
Share on other sites

Archived

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

×
×
  • Create New...

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.