php - The checkbox's do not hold all value when I select more then one checked -


i want insert employee attendance. when checked more 1 checkbox take 2 checkbox value 1 , other checkbox value 0 .so how can solve please me. form code

<form action="coll.php" method="post" name="create_grading" id="create_grading">           <table width="30%" border="0" cellpadding="2" cellspacing="3" class="maintable">             <tr>                 <th><input type="checkbox" id="selectall" /></th>                 <th>name</th>             </tr>             <?php             $sql = "select * employee";             $query = mysqli_query($con, $sql);             while ($row = mysqli_fetch_array($query)) {                 ?>                    <tr>                     <td><input type="hidden" name="eid[]" value="<?php echo $row['eid']; ?>"/>                         <input name="status[]" class="case" type="checkbox" value="1" /><input name="status[]" class="case" type="hidden" value="0" /></td>                     <td align="center"><?php echo $row['employee_name'] ?></td>                 </tr>             <?php }; ?>              <tr>                 <td></td>                 <td><input type="submit" name="submit" id="submit" value="submit" /></td>                    </tr>         </table>     </form> 

this insert code

$host = "localhost"; $user = "root"; $pass = ""; $db = "multiple_row_insert"; $con = mysqli_connect($host, $user, $pass, $db);   if (isset($_post['submit'])) {     $eid = $_post['eid'];     $count = count($eid);     ($i = 0; $i < $count; $i++) {         $status = $_post['status'][$i];         $eid2 = $_post['eid'][$i];         $query = "insert time(eid,status) values ('$eid2','$status')";         $query = mysqli_query($con, $query);     } } 

if(isset($_post['checkbox'])) //then checked... else //is not checked 

so need 1 checkbox, can change name of inputs. , in backend use like:

$_post['status_'.$i] 

on each case , detect if checked "isset" $_post.

edited:

your code should (not tested, sorry if there syntax error, can fix them anyways):

$host = "localhost"; $user = "root"; $pass = ""; $db = "multiple_row_insert"; $con = mysqli_connect($host, $user, $pass, $db);   if (isset($_post['submit'])) {     $eid = $_post['eid'];     $count = count($eid);     ($i = 0; $i < $count; $i++) {         $status = 0;         if(isset($_post['status_'.$i])) //check if checkbox setted (value 1 / checked)           $status = 1;         $eid2 = $_post['eid'][$i];         $query = "insert time(eid,status) values ('$eid2','$status')";         $query = mysqli_query($con, $query);     } } 

and frontend code:

<form action="coll.php" method="post" name="create_grading" id="create_grading">           <table width="30%" border="0" cellpadding="2" cellspacing="3" class="maintable">             <tr>                 <th><input type="checkbox" id="selectall" /></th>                 <th>name</th>             </tr>             <?php             $sql = "select * employee";             $query = mysqli_query($con, $sql);             $i = 0;             while ($row = mysqli_fetch_array($query)) {                 ?>                    <tr>                     <td><input type="hidden" name="eid[]" value="<?php echo $row['eid']; ?>"/>                         <input name="status_<?php echo $i; ?>" class="case" type="checkbox" value="0" /></td>                     <td align="center"><?php echo $row['employee_name']; ?></td>                 </tr>             <?php $i++; } ?>              <tr>                 <td></td>                 <td><input type="submit" name="submit" id="submit" value="submit" /></td>                    </tr>         </table>     </form>              

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -