php - store multiple checkboxes of the foreach loop to the mysql table -


the form have made

<input id="user_name" type="text" name="name" value="<?php echo (($row['name'] == $row['name'])? $row['name'] : '') ?>" disabled="disabled" /> <input id="user_email" type="text" name="email" value="<?php echo (($row['email'] == $row['email'])? $row['email'] : '') ?>" disabled="disabled" />  <?php foreach ($lists $list => $slug ) { ?>     <li colspan="2"><input type="checkbox" id="list" name="rights[]" <?php if($slug == 1 ){echo 'checked="checked"';}?> /> <?php echo $list; ?></li> <?php } ?> 

here checkboxes conditions: checkboxs "rights[]" 5 , each checkbox value 0/1, 0 if unchecked, 1 if checked (disable/enable)

i have created table store following

 <?php     $rights             = ($_post['rights']) ? $_post['rights'] : 0; //  $some_rights            = implode(',',$rights);  $conn->db_exec("insert %smoderator (id, name, email) values ('%d', '%s', '%s')", db_prefix, $log_id, $name, $email);  foreach ($rights $right) { $conn->db_exec("update %smoderator set able_toedit = '$right', able_todel = '$right', able_toblock = '$right', able_tomove = '$right', able_tomark = '$right' id = '$log_id' limit 1", db_prefix); } ?> 

i found 2 problems here 1. data sent through 2 step, insert 1st , update, have not succeeded making in insert only, looking more efficient process , secure 2. if tick 1,2 or more stored become 0 in table, how cope sent according amount of checked?, need advice , help, thanks


Comments