Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.