TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Array problems. (http://www.talkphp.com/general/4534-array-problems.html)

Matt 06-11-2009 04:50 PM

Array problems.
 
I'm having problems with my permissions system. What I'm trying to add is a feature to add a user group.

When adding the group, we have checkboxes with certain fields that come from information that is stored in the $perms array.

First off, I'm trying to make it so when a checkbox is checked by the permission value, it is 1, if its not checked, the value is 0, that is already done.

When I post my form, the error I receive is:

Fatal error: Unsupported operand types in C:\Program Files\xampp\htdocs\lenix\modules\test.php on line 50

I have never even had that error before.

The $perms array looks like this:
PHP Code:

<?php
$perms 
= array(    'forum' => array(
        
=> 'f_view',
        
=> 'f_post_topic',
        
=> 'f_post_reply',
        
=> 'f_attach',
        
=> 'f_manage_comment',
        
=> 'f_manage_cat',
        
=> 'f_moderator',
        
=> 'f_bypass_flood',
    ),    
    
'users' => array(
        
=> 'u_view_users',
        
=> 'u_view_online',
        
=> 'u_view_profile',
        
=> 'u_manage_users',
        
=> 'u_manage_groups',
    ),
)    

// So how I display these is like this:

foreach($GLOBALS['perms'] as $permgroup => $perms )
{
    echo 
$permgroup.'<br>';

    foreach( 
$perms as $bit => $name )
    {
        echo 
'--'.$name.'<br>';
    }
}
?>

Notice this isn't the full html, I have certain code for the check boxes, but that's not important right now.

All that displays all fine and everything, the html is perfectly fine, getting the post data shouldn't be a problem.

This is where my code goes wrong:

PHP Code:

<?php
// if any permissions were checked
if( $_POST['perms'] )
{
    
// for all of the groups that had any checked boxes
    
foreach($_POST['perms'] as $permgroup => $p)
    {
        
// for each item checked in the bitfield
        
foreach($p as $bit)
        {
            
// add the bit to the permission group
            
$perms[$permgroup] += $bit;
        }
    }
}

// the error is on this line of code:

// add the bit to the permission group
$perms[$permgroup] += $bit;
?>

Does anybody see anything out of the ordinary? I sure don't. This is why I'm asking for help, lol.

If anybody can point me in the right, or a better direction, that would be completely awesome, and I would be very thankful.

Thanks in advance.

Schroder 06-11-2009 08:30 PM

That particular error can occur when a non-numeric number is being used with the operator. (I was able to recreate this error with your code, but haven't been able to replicate it yet.) When using a string you want to use .= instead.

Without seeing the form it's hard to tell what should be processed in the loops.

I think what might be happening is the post data is being overwritten by one of the lines using the $perms variable. This really depends on how your environment is setup, and how everything is scripted.

Let me know if this helps. If you can provide a more information on what the form is submitting I could probably make more sense of this.


All times are GMT. The time now is 01:48 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0