Binty 0 Newbie Poster

**how to check data by multivalue of array checkbox in multi row one column.
**
Hi, im need to checked data from database from checkbox multivalue of array, then insert into tabel in multirow one column.
I try to insert same value (month) in student payment but the data still insert to the tabel, and it should show alerts.
I confusing how to check data with array and how show the alert, in this case?
pls help...
I'm new here..
and this is my code.

<!--form -->

<tr>
 <td>ID Student</td>
 <td>:</td> 
 <td><input name="id_student" type="text" id="nis" value="<?= $row['id_student']?>" readonly="readonly"/></td>
</tr>
<tr>
 <td>Month</td>
 <td>:</td>
 <td>
  <label class="checkbox inline"><input type="checkbox" name="month[]" value="1"> Jan
  </label>
  <label class="checkbox inline"><input type="checkbox" name="month[]" value="2"> Feb</label>
  <label class="checkbox inline"><input type="checkbox" name="month[]" value="3"> Mar</label>
  <label class="checkbox inline"><input type="checkbox" name="month[]" value="4"> Apr</label>
  <label class="checkbox inline"><input type="checkbox" name="month[]" value="5"> Mei</label>
  <label class="checkbox inline"><input type="checkbox" name="month[]" value="6"> Jun</label>
  <label class="checkbox inline"><input type="checkbox" name="month[]" value="7"> Jul</label>
  <label class="checkbox inline"><input type="checkbox" name="month[]" value="8"> Agt</label>
  <label class="checkbox inline"><input type="checkbox" name="month[]" value="9"> Sep</label>
  <label class="checkbox inline"><input type="checkbox" name="month[]" value="10"> Okt</label>
  <label class="checkbox inline"><input type="checkbox" name="month[]" value="11">Nov</label>
  <label class="checkbox inline"><input type="checkbox" name="month[]" value="12">Des</label>
</td>

/form action/

    <?php

    $transaction_id = $_POST['transaction_id'];
    $id_student     = $_POST['id_student'];
    $spp            = $_POST['spp'];
    $praktek        = $_POST['praktek'];
    $tabungan       = $_POST['tabungan'];
    $osis           = $_POST['osis'];
    $month          = $_POST['month'];

    $sum = count ($month);
    echo $sum;

    if (isset($_POST['month'])){
        $checkedPay =mysql_num_rows(mysql_query
            ("SELECT m.id_month 
            FROM month_pay m
            INNER JOIN transaction t
            INNER JOIN student s 
            ON t.id_student = s.id_student
            AND m.transaction_id = t.transaction_id where m.id_month='$month' AND t.id_student='$id_student'"
        ));     
        if($checkedPay>0){ 
             echo "have been paid.";
             echo "<script type=\"text/javascript\">alert('failed!');"."history.go(-1)</script>";
        }
        else{
            $query1=mysql_query ("insert into transaction(transaction_id , id_student, nominal_spp, nominal_praktek, nominal_tabungan, nominal_osis, date_pay ) 
            values('','$id_student','$spp', '$praktek', '$tabungan', '$osis', SYSDATE() )");            
            if($sum >=1){
                foreach ($month as $a ){
                    mysql_query("insert into month_pay (transaksi_id, id_month) values(LAST_INSERT_ID(), '$a')");
                }
            } 
        }
    }
    ?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.