0

I have checkbox inside looping like this.

<?php

for($i=0;$i<$jumlah;$i++)  {

     echo "<tr>
          <td align='center'><input type='text' name='PROSES[]' placeholder='Input Proses $i'/></td>
          <td align='center'><input type='checkbox' name='NOTIF[]'  value='Yes'/></td>
          <td align='center'> <input type='checkbox' name='REMINDER[]'  value='Yes'/></td>
          <td align='center'> <input type='checkbox' name='DECISION[]'  value='Yes'/></td>
          <td align='center'> <input type='checkbox' name='AUTHOR[]'  value='Yes'/></td>
          <td align='center'><input type='text' name='SIAPA[]' size='40' placeholder='dari siap ke siapa' /></td>
      </tr>";


}//end for

echo "</table>"; 

?>

and the query to input like this

if(isset($_POST['SUBMIT'])) {
  $proses = $_POST[PROSES];//value from selectbox
  $jumlah = count($proses);

$max_id = $data_max_id[ID];

        for($i=0;$i<$jumlah;$i++) {

            $query_input = "INSERT INTO data_proses SET ID_input       = '$max_id',
                                                        proses         = '$proses[$i]',
                                                        notifikasi     = '$notif[$i]',
                                                        reminder       = '$reminder[$i]',
                                                        decision       = '$decision[$i]',
                                                        authorization  = '$author[$i]',
                                                        dari_siapa     = '$siapa[$i]'";

            $hasil_input = mysqli_query($mysqli, $query_input);                                                     
        }//end for
}

it will Produce table like this

enter image description here

In Short,

After I have submit to mysql is successfull But stil wrong. IF I have Check like that image the database have wrong result like this

enter image description here

input :
        [x][x][ ][ ]
        [ ][x][x][ ]
        [ ][ ][x][x]

On database : 

        [x][x][x][x]
        [ ][x][x][ ]
        [ ][ ][ ][ ]

Can anyone help to fix my problem?

Thanks in advance

2
  • 1
    It'd be best if you show the code that inserts/saves to the database. Commented Apr 14, 2015 at 3:16
  • 1
    When you submit checkboxes, only the checked ones are submitted. You need to give them values that tell you which row the checkbox is onl Commented Apr 14, 2015 at 3:17

1 Answer 1

1

Include the row number in the names of all the checkboxes. Only the checked boxes get submitted, and PHP will index them all from 0 if they don't have an explicit index -- you won't see empty values for the checkboxes that are skipped.

for($i=0;$i<$jumlah;$i++)  {

     echo "<tr>
          <td align='center'><input type='text' name='PROSES[]' placeholder='Input Proses $i'/></td>
          <td align='center'><input type='checkbox' name='NOTIF[$i]'  value='Yes'/></td>
          <td align='center'> <input type='checkbox' name='REMINDER[$i]'  value='Yes'/></td>
          <td align='center'> <input type='checkbox' name='DECISION[$i]'  value='Yes'/></td>
          <td align='center'> <input type='checkbox' name='AUTHOR[$i]'  value='Yes'/></td>
          <td align='center'><input type='text' name='SIAPA[]' size='40' placeholder='dari siap ke siapa' /></td>
      </tr>";


}//end for
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.