Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Mar 2009
    Location
    United Kingdom
    Posts
    161
    Thanks
    6
    Thanked 28 Times in 28 Posts

    Forum permissions

    Im trying to get group forum permissions fully customizable, so when an admin creates a new group it will automaticly create a set of default permissons for the newly made group for each forum present, but as of this moment it only creates the group but not permissions as well.

    Heres my code.

    PHP Code:
    if(isset($_POST['gadd'])){
        
    $gname=$_POST['gname'];
        
    $sql="INSERT INTO groups (group_name) VALUES ('$gname')";
        
    $result=mysql_query($sql);
        
        
    //permissons
        
        
    $sql="SELECT * FROM groups WHERE group_name='$gname'";
        
    $result=mysql_query($sql);
        
    $rows=mysql_fetch_array($result);
        
        
    $gid=$rows['group_id'];
        
        
    $sql="SELECT * FROM forums";
        
    $result=mysql_query($sql);
        
        while(
    $rows=mysql_fetch_array($result)){
            
    $forumid=$rows['id'];
            
    $sql2="INSERT INTO groups_perm (group_id, forum_id, read, write) VALUES ('$gid', '$forumid', '0', '0')";
            
    $result2=mysql_query($sql2);
        }

    Any help would be great.

  • #2
    Regular Coder kokjj87's Avatar
    Join Date
    Sep 2008
    Location
    Singapore
    Posts
    279
    Thanks
    1
    Thanked 55 Times in 54 Posts
    If you are making your own forum...

    I would recommended the Zend Acl library.. it is very well written, very flexible, very easy to use... You don't need to use a Zend framework in order to use this Acl library...

    How to use it:
    http://codeigniter.com/forums/viewthread/60378/
    http://framework.zend.com/manual/en/zend.acl.html

    It will take you some time to fully understand it...

  • #3
    Regular Coder
    Join Date
    Mar 2009
    Location
    United Kingdom
    Posts
    161
    Thanks
    6
    Thanked 28 Times in 28 Posts
    Hmm that would mean changing ALL my code, im not too fond of doing this, anyone got a solution to my problem.

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    First thing you have to do is add error checking to every query you run. Every time you call mysql_query(), you must check to make sure it worked. You don't have to echo the error-- you can write it a log, or whatever-- but you have to know if the query worked or not before you go on.

    PHP Code:
    $result=mysql_query($sql); 
    if (!
    $result) {
        die(
    "SQL error. Query is $sql<br>Error is ".mysql_error());

    Once you do that, you'll probably discover why your script isn't getting that second insert into groups_perm done. (If i had to guess, it's because you are enclosing an integer value in quotes)

    One other note: There's no need to select the row you just inserted in order to find the ID that was created. Just use mysql_insert_id().

    http://us.php.net/manual/en/function...-insert-id.php

  • Users who have thanked Fumigator for this post:

    Killermud (03-16-2009)

  • #5
    Regular Coder
    Join Date
    Mar 2009
    Location
    United Kingdom
    Posts
    161
    Thanks
    6
    Thanked 28 Times in 28 Posts
    Ok i added this in and it came up with the following error :

    SQL error. Query is INSERT INTO groups_perm (group_id, forum_id, read, write) VALUES ('5', '1', '0', '0')
    Error is You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read, write) VALUES ('5', '1', '0', '0')' at line 1

    I suppose this means i cannot have interger values for my read and write, yes?

  • #6
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    No... that wasn't the problem, though you shouldn't be enclosing integers in quotes anyway. Take a look at the list of reserved words for MySQL 5.0:

    http://dev.mysql.com/doc/refman/5.0/...ved-words.html

    Don't use any of these words as table or column names.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •