View Full Version : Forum permissions

03-16-2009, 01:35 AM
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.

$sql="INSERT INTO groups (group_name) VALUES ('$gname')";


$sql="SELECT * FROM groups WHERE group_name='$gname'";


$sql="SELECT * FROM forums";

$sql2="INSERT INTO groups_perm (group_id, forum_id, read, write) VALUES ('$gid', '$forumid', '0', '0')";

Any help would be great.

03-16-2009, 06:12 AM
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:

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

03-16-2009, 07:53 PM
Hmm that would mean changing ALL my code, im not too fond of doing this, anyone got a solution to my problem.

03-16-2009, 08:45 PM
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.

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().


03-16-2009, 08:54 PM
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?

03-16-2009, 09:24 PM
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:


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