John Davidson

php - insert Multiple Checkbox Value different name in mysql database

0 comments
Message:


i have table admin_rouls


Through it, I control the setting of the admin's permission for the category topics


i try to give each admin permission


for example admin id 9 give him permission to category id 20 can edit or add new topic but cant delete


ID  admin_id   cat  can_add  can_edit  can_del
1 9 20 Y Y N
2 9 19 N Y N
3 9 18 N N Y

i used this form


<form method="post">
<?php
$GetCats=mysqli_query($db,"select * from section where id_sec = 0");
while($rowCat=mysqli_fetch_object($GetCats))
{
echo $rowCat->name ;

echo '<div class="pull-left">

ADD
<input type="checkbox" name="add_cat['.$rowCat->id.']" >

EDIT
<input type="checkbox" name="edit_cat['.$rowCat->id.']" >

DELETE
<input type="checkbox" name="del_cat['.$rowCat->id.']" >

</div>';
}
?>
<input type="hidden" name="AdminId" value="<?php echo $_GET['id'];?>">
<input type="submit" name="submit" value="save">
</form>

post data come like that


add_cat[50]=on&edit_cat[50]=on&del_cat[50]=on&add_cat[100]=on&edit_cat[100]=on&edit_cat[70]=on&del_cat[70]=on&AdminId=5&submit=save


I have a problem how insert this data to database table
with many category id same 50 100 70 and option same add_cat edit_cat del_cat


ID  admin_id   cat  can_add  can_edit  can_del
1 9 20 Y Y N
2 9 19 N Y N
3 9 18 N N Y

any idea ??



My Answer:

Category 20

Category 19

Category 18



And in your insert.php file, you can insert the values into the database like this:
php
query($sql);
}
// Close the database connection
$conn->close();
echo "Permissions updated successfully";
}
?>

This code will insert the selected categories with their corresponding permissions into the admin_roles table for the admin with id 9.

Rate this post

4 of 5 based on 3539 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us