Jump to content

in_array problem


lew14

Recommended Posts

I need some help as I understand very little about php so can someone help me with this problem.

 

am getting the following error

 

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 79

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 79

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 79

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 79

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 79

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 79

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 79

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 87

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 87

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 87

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 87

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/paid2/public_html/admin2/mod_manage_level.php on line 108

 

I am going to attach file that it refers to and maybe someone can help explain to me what is wrong.  I do ot know about php so if it is not to much trouble so I know next time can someone explain the in_array definition?  I have tried to find out but it is a bit confusing.

 

Thank you,

Lisa

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

Well in_array() works like so.

 

The first argument is the needle, which is what you want to search for in the haystack, which is the second argument. So basically that error is telling you that the second argument you gave was not an array. Make sure that the $items variable is in fact an array. You can check by putting this on Line 104:

 

print_r($items);

 

It should display something along the lines of:

 

Array ( something_here => Something else here )

 

Also, you have spelt if as "iif".

Link to comment
Share on other sites

iif (a.k.a instant if) is a common function in many programming languages. PHP doesn't have it AFAIK, but it can easily be implemented.

 

<?php
function iif($expression, $returntrue, $returnfalse = '') {
    return ($expression ? $returntrue : $returnfalse);
} 

 

(Code from http://www.phpit.net/code/iif-function )

 

So it might be that it's actually included in this script

 

 

(BTW: The code above shows, why PHP doesn't need iif(). There's ternary operator instead ;) )

Link to comment
Share on other sites

Hi,

 

Use,  iif(in_array($mod_array[0],(array)$items).

 

The warning will come if the second argument is not an array. So put (array) in front of the array variable ($items). The same should be added for all array functions otherwise it will show up warning if the argument is not an array.

 

Link to comment
Share on other sites

Thanks for the help with the in_array problem all the errors on the webpage are gone.  I changed to this and now I am getting the following error and it won't post to database.

 

Line: 80

Character: 2

"null" is null or not an object

Error: 0

 

What does this mean and can it be fixed?

 

<?

$includes[title]="Moderator Level Manager";

include('admin2/mod_manage_arrays.php');//lots of info, put it in a seperate file

if(isset($_GET['action'])){

$ability=$_POST['ability'];

 

if($ability!=''){

foreach($ability as $non_menu_check){//pulls each ability into a variable

if(array_key_exists($non_menu_check,$non_menu_array)){

foreach($non_menu_array[$non_menu_check] as $non_menu_item){

$non_menu_list.=','.$non_menu_item;

}

}

}

 

$non_menu_list=ltrim($non_menu_list,',');

$menu_list=join($ability,',');

$edit_user=$_POST['edit_user'];

$ad_manage=$_POST['ad_manage'];

if($edit_user=='none') $edit_user='';

if($ad_manage=='none') $ad_manage='';

 

if($_POST['id']=='new'){

 

$Db1->query("INSERT INTO mod_permissions (group_name,menu_ids,non_menu,edit_user,edit_ads) VALUES ('{$_POST['name']}','$menu_list','$non_menu_list','$edit_user','$ad_manage')");

}else{

$Db1->query("UPDATE mod_permissions SET group_name='{$_POST['name']}', menu_ids='$menu_list', non_menu='$non_menu_list', edit_user='$edit_user', edit_ads='$ad_manage' WHERE id='$id'");

}

}

$Db1->sql_close();

header("Location: admin.php?view=admin&ac=mod_manage&saved=true&".$url_variables);

exit;

}

 

if($id != 'new'){

$sql=$Db1->query("SELECT * FROM mod_permissions WHERE id='$id'");

while($db_info=$Db1->fetch_array($sql)){

$group_name=$db_info['group_name'];

$edit_ads=$db_info['edit_ads'];

$edit_user=$db_info['edit_user'];

$items=explode(',',$db_info['menu_ids']);

 

}

}else{

$mod_array=array();

$items=array();

}

 

$includes[content].="

<script>

function CA(isOnload) {

for (var i=0;i<document.frm.elements.length;i++) {

var e = document.frm.elements;

if ((e.name != 'allbox') && (e.type=='checkbox')) {

if (isOnload != 1) {

if (e.checked != document.frm.allbox.checked) {

e.click()

 

}

//hL(e, true)

}

}

}

alert(\"Note: User and Ad permissions were not changed\");

}

</script>

 

<div align='right'><a href='admin.php?view=admin&ac=mod_manage&{$url_variables}'>Back to Moderator Manger</a></div>

Here you can change the permissions of a moderator group.

<form action=\"admin.php?view=admin&ac=mod_manage_level&action=run&{$url_variables}\" method=\"POST\" name=\"frm\"><br \>

Group Name: <input type=\"text\" name=\"name\" size=\"40\" value=\"$group_name\"><br \>

Select All: <input type=\"checkbox\" value=\"1\" name=\"allbox\" onClick=\"CA()\"><br \>

";

 

 

foreach($logs_stats_array as $mod_array){

$table_data_logs.="<tr class=\"tableHL2\" onmouseover=\"this.className='tableHL3'\" onmouseout=\"this.className='tableHL2'\">

<td>{$mod_array[1]}</td>

<td><div align='center'><input name=\"ability[]\" type=\"checkbox\" value=\"{$mod_array[0]}\"".iif(in_array($mod_array[0],(array)$items)," checked='checked'")."></div></td>

</tr>";

}

 

foreach($mod_pages_array as $mod_array){

$table_mod_pages.="<tr class=\"tableHL2\" onmouseover=\"this.className='tableHL3'\" onmouseout=\"this.className='tableHL2'\">

<td>{$mod_array[1]}</td>

<td><div align='center'><input name=\"ability[]\" type=\"checkbox\" value=\"{$mod_array[0]}\"".iif(in_array($mod_array[0],(array)$items)," checked='checked'")."></div></td>

</tr>";

}

 

$table_edit_view.="<tr class=\"tableHL2\" onmouseover=\"this.className='tableHL3'\" onmouseout=\"this.className='tableHL2'\">

<td>User Manager</td>

<td><div align='center'><input name=\"edit_user\" type=\"radio\" value=\"view\"".iif($edit_user=='view'," checked='checked'")."></div></td>

<td><div align='center'><input name=\"edit_user\" type=\"radio\" value=\"edit\"".iif($edit_user=='edit'," checked='checked'")."></div></td>

<td><div align='center'><input name=\"edit_user\" type=\"radio\" value=\"none\"".iif($edit_ads=='' && $id!='new'," checked='checked'")."></div></td>

</tr>

<tr class=\"tableHL2\" onmouseover=\"this.className='tableHL3'\" onmouseout=\"this.className='tableHL2'\">

<td>Ad Manager</td>

<td><div align='center'><input name=\"ad_manage\" type=\"radio\" value=\"view\"".iif($edit_ads=='view'," checked='checked'")."></div></td>

<td><div align='center'><input name=\"ad_manage\" type=\"radio\" value=\"edit\"".iif($edit_ads=='edit'," checked='checked'")."></div></td>

<td><div align='center'><input name=\"ad_manage\" type=\"radio\" value=\"none\"".iif($edit_ads=='' && $id!='new'," checked='checked'")."></div></td>

</tr>";

 

foreach($admin_feat_array as $mod_array){

$table_admin_feat.="<tr class=\"tableHL2\" onmouseover=\"this.className='tableHL3'\" onmouseout=\"this.className='tableHL2'\">

<td>{$mod_array[1]}</td>

<td><div align='center'><input name=\"ability[]\" type=\"checkbox\" value=\"{$mod_array[0]}\"".iif(in_array($mod_array[0],(array)$items)," checked='checked'")."></div></td>

</tr>";

}

 

$includes[content].="Logs and Stats:

<br \>

<table class=\"tableBD1\"><tr class=\"tableHL1\">

<td><b>Permission:</b></td>

<td><b>Can View</b></td>

</tr>

$table_data_logs

</table><br \>

Moderator Functions:

<table class=\"tableBD1\"><tr class=\"tableHL1\">

<td><b>Permission:</b></td>

<td><b>Can View</b></td>

</tr>

$table_mod_pages

</table><br \>

Edit or View Functions:

<table class=\"tableBD1\"><tr class=\"tableHL1\">

<td><b>Permission:</b></td>

<td><b>Can View</b></td>

<td><b>Can Edit</b></td>

<td><b>Cannot View</b></td>

</tr>

$table_edit_view

</table><br \>

Administrator Functions:

<table class=\"tableBD1\"><tr class=\"tableHL1\">

<td><b>Permission:</b></td>

<td><b>Can View</b></td>

</tr>

$table_admin_feat

</table>

<br \><br \>

<input type=\"hidden\" name=\"id\" value=\"$id\">

<input type=\"submit\" value=\"Submit\" name=\"submit\">

</form>

";

 

 

 

 

 

?>

Link to comment
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.