Answer the question
In order to leave comments, you need to log in
How to populate checkboxes from a request?
Hello. Read a lot about the differentiation of rights. Many solutions are inefficient, many are not clear.
Implemented his own, for the project. The bottom line is this: there is a role table, which lists the roles:
1. admin
2. Client 3.
Manager
4. Master, etc.
There is a right table, where the rights are:
1. access to the
admin panel 2. adding applications
3. editing applications
4. adding users
Well, the third access is for linking these two tables.
In the right place I write:
<?$right='4'; include('access.php');if(isset($access['id'])){
echo "доступно только если у пользователя с ролью админ есть право 4"; }?>
<?php
//проверка прав доступа
$dostup = mysqli_query($db, "SELECT id FROM access WHERE id_right = $right AND id_role = $user[role] ");
$access = mysqli_fetch_assoc($dostup);
$access1 = mysqli_query($db,"SELECT id_right FROM access WHERE id_role = '$_GET[id]'");
if($ass = mysqli_fetch_array($access1)){
do{
print_r($ass['id_right']);
//Скрипт выдает 1,2,3 или 4 и т.д. В зависимости от выбора $_GET[id]
}while($ass = mysqli_fetch_array($access1));
}
<div class="checkbox"><label><input type="checkbox" name="dostup-3" value="on" /> Доступ в административную панель</label></div>
<div class="checkbox"><label><input type="checkbox" name="dostup-1" value="on" /> Добавление и редактирование заявок</label></div>
<div class="checkbox"><label><input type="checkbox" name="dostup-2" value="on" /> Удаление заявок</label></div>
<div class="checkbox"><label><input type="checkbox" name="dostup-4" value="on" /> Быстрое обслуживание</label></div>
<div class="checkbox"><label><input type="checkbox" name="dostup-5" value="on" /> Управление ролямя</label></div>
Answer the question
In order to leave comments, you need to log in
First, a few words on security and performance:
SQL injection. A lot has been written on this topic, check all the data from outside.
works slower than:
I didn’t quite understand about checkboxes. If you need the checkbox to become active when some condition is triggered, then:
$ac = array();
$access1 = mysqli_query($db,"SELECT id_right FROM access WHERE id_role = '$_GET[id]'");
if($ass = mysqli_fetch_array($access1)){
do{
$ac[] = $ass['id_right'];
}while($ass = mysqli_fetch_array($access1));
}
<div class="checkbox"><label><input type="checkbox" name="dostup-3" value="on" <?php
echo ( in_array(1, $ac) ) ? 'checked' : '' ;
?> /> Доступ в административную панель</label></div>
<div class="checkbox"><label><input type="checkbox" name="dostup-1" value="on" <?php
echo ( in_array(2, $ac) ) ? 'checked' : '' ;
?> /> Добавление и редактирование заявок</label></div>
<div class="checkbox"><label><input type="checkbox" name="dostup-2" value="on" <?php
echo ( in_array(3, $ac) ) ? 'checked' : '' ;
?> /> Удаление заявок</label></div>
<div class="checkbox"><label><input type="checkbox" name="dostup-4" value="on" <?php
echo ( in_array(4, $ac) ) ? 'checked' : '' ;
?> /> Быстрое обслуживание</label></div>
<div class="checkbox"><label><input type="checkbox" name="dostup-5" value="on" /> Управление ролямя</label></div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question