#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    11
    Rep Power
    0

    Small code giving some errors


    I have a small code which makes regular members forum moderators on specific forums/topics.
    While this works and i'm more than happy with it the only issue i get is if i set the option on a member to be forum moderator, but i dont select which topics i will receive error when editing other options from his profile.
    And the error is specific to the forum moderator code.

    https://pastebin.com/aEdV6Uy0

    The error i receive when forum moderator is set to yes but not selected any topics is " Invalid argument supplied for foreach()" and " join(): Invalid arguments passed"
    It doesnt matter what option from the members profile i change as long as forum moderator is set to yes and no topics are selected it will bork.
  2. #2
  3. Backwards Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,916
    Rep Power
    9646
    If you don't select any options then what are you trying to give them permissions for? I'm not talking about the code here but what you expect to happen.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    11
    Rep Power
    0
    Yes i understand this, its pretty obvious, but what to do to just let it without any selected topics but with the option set to yes?
    I mean maybe i would add at a further time on which topics it should have access. And this way it wont popup any unexpected errors while editing other option on the members profile.
  6. #4
  7. Backwards Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,916
    Rep Power
    9646
    So you keep talking about topics but the code there only seems to be dealing with forums. Those error messages you're citing would come from having forums_count > 0 (I don't know how that happens), forum_special != "no" (ditto), but no forums_* options marked. Nothing about topics.
    I'm asking what you expect to happen because clearly this code expects you to pick forums, so if you're not picking forums then I don't know what you're trying to accomplish.

    But to answer the question that I think you're asking of how to get rid of the error messages,

    The errors are because there were no forums selected, which means the $foo array is never created with any items, which means trying to foreach it is a problem. It also means $boo and $boo1 are never created with any items either, so trying to join() them is also a problem.
    You can fix the "never created" issues by setting up initial values for the three variables.
    PHP Code:
    // before the for loop
    $foo $boo $boo1 = array(); 
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    11
    Rep Power
    0
    I understand that the code works like this. And of course if there is no data feed to it will give that bork error.
    Also inserted what you said and it still gives error, but no sign of the foreach one.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    11
    Rep Power
    0
    Inserted that just before
    PHP Code:
     for ($i 1$i $forumc 1$i++) { 
  12. #7
  13. Backwards Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,916
    Rep Power
    9646
    Then what's your code now? And are you sure you're posting the right code according to the line number in the error message? And what error message?

IMN logo majestic logo threadwatch logo seochat tools logo