使用checkbox..how组使其插入数据库并可以在PHP中显示它?

时间:2014-11-05 15:08:26

标签: php mysql

当用户选择CheckBox时,应将其名称插入数据库并显示。我根据他们的名字为每个CheckBox组创建了许多表。我希望CheckBox的每个群组都在不同的表格中插入CheckBox的值。在数据库中的名称..让我们说我在数据库中有9个表名。在网站上,我有9个类别的ChecBox名称。因此用户将选择并勾选。勾选后,已勾选的值将插入到数据库中,并将显示该ChecBox的名称。我已尝试使用ChecBox语句将insert的数据插入数据库,但它没有用!

CHECKBOX表格

  <form id="form1" name="form1" method="post" action="" >
  <tr>
     <td height="34" bgcolor="#A4DDED" class="style21"></td>
     <td width="792" bgcolor="#A4DDED" class="style21">
     <br>
     <input name="docu[]" type="checkbox" value="BMK81A"/> <label for="BMK81A">BMK81A</label><br>
     <input name="docu[]" type="checkbox" value="BMK81"/> <label for="BMK81">BMK81</label><br>
     <input name="docu[]" type="checkbox" value="DL3"/> <label for="DL3">JPN-DL-3 / JPN-DL-3</label><br>
     <input name="docu[]" type="checkbox" value="DL2"/> <label for="DL2">JPN-DL-2</label><br>
     <input name="docu[]" type="checkbox" value="DL1"/> <label for="DL1">JPN-DL-1</label><br>

       <br>
       <br>

     <fieldset class="group">
        <legend>PM</legend>
        <ul class="checkbox">
        <li>
        <input name="docu[]" type="checkbox" id="SSK" value="1" />
         <label for="SSK">SSK</label>
         </li>
        <li>
        <input name="docu[]" type="checkbox" id="PM" value="1" />
        <label for="PM">PM</label>
           </li>
           <li>
            <input name="docu[]" type="checkbox" id="PP" value="1" />
            <label for="PP">Passport</label>
            </li>
          <li>
            <input name="docu[]" type="checkbox" id="PT" value="1" />
           <label for="PT">PT</label>
          </li>
         <li>
        <input name="docu[]" type="checkbox" id="AT" value="1" />
        <label for="PAT">Perakuan Taraf</label>
        </li>
        <li>
        <input name="docu[]" type="checkbox" id="SAA" value="1" />
        <label for="SAA">SSA/label>
        </li>
        <li>
        <input name="docu[]" type="checkbox" id="BW" value="1" />
        <label for="BW">Borang W</label>
        </li>
        <li>
        <input name="docu[]" type="checkbox" id="DS" value="1" />
        <label for="DS">DS</label>
        </li>
        <li>
        <input name="docu[]" type="checkbox" id="APP" value="1" />
        <label for="APP">Akuan Penerimaan Permohonan</label>
        </li>
        <li>
        <input name="docu[]" type="checkbox" id="RE1" value="1" />
        <label for="RE1">RE1</label>
         </li>
        <li>
        <input name="docu[]" type="checkbox" id="LU2" value="1" />
        <label for="LU2">LU2</label>
        </li>
        <li>
        <input name="docu[]" type="checkbox" id="NPT" value="1" />
        <label for="NPT">NPT</label>
        </li>
         <li>
        <input name="docu[]" type="checkbox" id="SRP" value="1" />
        <label for="SRP">SRP</label>
        </li>
        <li>
        <input name="docu[]" type="checkbox" id="KDP" value="1" />
        <label for="KDP">KDP</label>
       </li>
       </ul>
      </fieldset>
     <br>
      <br>

        <fieldset class="group">
        <legend>IB</legend>
        <ul class="checkbox">
        <li>
        <input name="docu[]" type="checkbox" id="SSW" value="1" />
        <label for="SSW">SSW</label>
         </li>
         <li>
        <input name="docu[]" type="checkbox" id="SSK" value="1" />
        <label for="SSK">SSK</label>
        </li>
        <li>
        <input name="docu[]" type="checkbox" id="PM" value="1" />
        <label for="PM">PM</label>
        </li>PM
        <li>
        <input name="docu[]" type="checkbox" id="PP" value="1" />
        <label for="PP">PP</label>
        </li>
        <li>
        <input name="docu[]" type="checkbox" id="KP" value="1" />
        <label for="KP">KP</label>
         </li>
        <li>
        <input name="docu[]" type="checkbox" id="BW" value="1" />
        <label for="BW">Borang W</label>
        </li>
        <li>
        <input name="docu[]" type="checkbox" id="DS" value="1" />
        <label for="DS">DS</label>
        </li>
        <li>
        <input name="docu[]" type="checkbox" id="APP" value="1" />
        <label for="APP">APP</label>
         </li>
        <li>
        <input name="docu[]" type="checkbox" id="RE1" value="1" />
        <label for="RE1">RE1</label>
        </li>
        <li>
        <input name="docu[]" type="checkbox" id="LU2" value="1" />
        <label for="LU2">LU2</label>
        </li>
        <li>
        <input name="docu[]" type="checkbox" id="NPT" value="1" />
        <label for="NPT">NPT</label>
        </li>
        <li>
        <input name="docu[]" type="checkbox" id="SRP" value="1" />
        <label for="SRP"></label>
        </li>
        </ul>
       </fieldset>
                <br>
                     <br>

            <fieldset class="group">
                <legend>&nbsp;BP</legend>
                 <ul class="checkbox">
                        <li>
                       <input name="docu[]" type="checkbox" id="SSW" value="1" />
                      <label for="SSW">SSW</label>
                 </li>
                  <li>
                   <input name="docu[]" type="checkbox" id="SSK" value="1" />
                     <label for="SSK">SSK</label>
                    </li>
                      <li>
                      <input name="docu[]" type="checkbox" id="PM" value="1" />
                      <label for="PM">Permit Masuk</label>
                    </li>
                     <li>
                     <input name="docu[]" type="checkbox" id="PP" value="1" />
                     <label for="PP">Passport</label>
                      </li>
                      <li>
                     <input name="docu[]" type="checkbox" id="KP" value="1" />
                     <label for="KP">KP</label>
                       </li>
                       <li>
                          <input name="docu[]" type="checkbox" id="BW" value="1" />
                          <label for="BW">BW </label>
                      </li>
                      <li>
                          <input name="docu[]" type="checkbox" id="DS" value="1" />
                            <label for="DS">DS</label>
                       </li>
                      <li>  
                      <input name="docu[]" type="checkbox" id="APP" value="1" />
                       <label for="APP">Akuan Penerimaan Permohonan</label>
                       </li>
                           <li>
                          <input name="docu[]" type="checkbox" id="RE1" value="1" />
                            <label for="RE1">RE1</label>
                           </li>
                             <li>
                             <input name="docu[]" type="checkbox" id="LU2" value="1" />
                             <label for="LU2">LU2</label>
                                </li>
                                 <li>
                               <input name="docu[]" type="checkbox" id="NPT" value="1" />
                               <label for="NPT">NPT</label>
                             </li>
                             <li>
                            <input name="docu[]" type="checkbox" id="SRP" value="1" />
                                <label for="SRP">SRP</label>
                              </li>
                           </ul>
                         </fieldset>
                           <br>
                          <br>


                      <fieldset class="group">
                           <legend>PF</legend>
                           <ul class="checkbox">
                         <li>
                         <input name="docu[]" type="checkbox" id="SSW" value="1" />
                         <label for="SSW">SSW</label>
                          </li>
                            <li>
                        <input name="docu[]" type="checkbox" id="SSK" value="1" />
                        <label for="SSK">SSK</label>
                          </li>
                          <li>
                           <input name="docu[]" type="checkbox" id="PM" value="1" />
                               <label for="PM">PM</label>
                              </li>
                               <li>
                             <input name="docu[]" type="checkbox" id="PP" value="1" />
                            <label for="PP">Passport</label>
                                 </li>
                                 <li>
                               <input name="docu[]" type="checkbox" id="KP" value="1" />
                                <label for="KP">KP</label>
                               </li>
                                   <li>
                                  <input name="docu[]" type="checkbox" id="BW" value="1" />
                                  <label for="BW">BW</label>
                                          </li>
                                        <li>
                                 <input name="docu[]" type="checkbox" id="DS" value="1" />
                                     <label for="DS>DS</label>
                                  </li>
                                     <li>
                                 <input name="docu[]" type="checkbox" id="APP" value="1" />
                                 <label for="BW">APP</label>
                                 </li>
                                  <li>
                                   <input name="docu[]" type="checkbox" id="RE1" value="1" />
                                  <label for="RE1">RE1</label>
                                      </li>
                                      <li>
                                    <input name="docu[]" type="checkbox" id="LU2" value="1" />
                                     <label for="LU2">LU2</label>
                                    </li>
                                      <li>
                                      <input name="docu[]" type="checkbox" id="NPT" value="1" />
                                         <label for="NPT">NPT</label>
                                         </li>
                                           <li>
                                           <input name="docu[]" type="checkbox" id="SRP" value="1" />
                                          <label for="SRP">SRP</label>
                                             </li>
                                               <li>
                                            <input name="docu[]" type="checkbox" id="KTDP" value="1" />
                                            <label for="KTDP">KTDP</label>
                                            </li>
                                            </ul>
                                               </fieldset>
                                                <br>
                                                <br>

                                       <fieldset class="group">
                                        <legend>AD</legend>
                                           <ul class="checkbox">
                                                      <li>
                                        <input name="docu[]" type="checkbox" id="SSK" value="1" />
                                         <label for="SSK">SSK</label>
                                         </li>
                                           <li>
                                         <input name="docu[]" type="checkbox" id="PM" value="1" />
                                          <label for="PM">PM</label>
                                        </li>
                                             <li>
                                        <input name="docu[]" type="checkbox" id="PP" value="1" />
                                                 <label for="PP">PP</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="KP" value="1" />
        <label for="KP">Kad Pengenalan</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="DS" value="1" />
        <label for="DS">DS</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="APP" value="1" />
        <label for="APP">APP</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="RE1" value="1" />
        <label for="RE1">REI</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="LU2" value="1" />
        <label for="LU2">LU2</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="NPT" value="1" />
        <label for="NPT">NPT</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="SRP" value="1" />
        <label for="SRP">SRP</label>
      </li>
    </ul>
    </fieldset>
  <br>
  <br>

  <fieldset class="group">
    <legend>SM</legend>
    <ul class="checkbox">
      <li>
        <input name="docu[]" type="checkbox" id="SSK" value="1" />
        <label for="SSK">SSK</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="PM" value="1" />
        <label for="PM">PM</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="PP" value="1" />
        <label for="PP">Passport</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="KP" value="1" />
        <label for="KP">KP</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="DS" value="1" />
        <label for="DS">Dokumen-dokumen Sokongan</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="APP" value="1" />
        <label for="APP">APP</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="RE1" value="1" />
        <label for="RE1">RE1</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="LU2" value="1" />
        <label for="LU2">LU2</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="NPT" value="1" />
        <label for="NPT">NPT</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="SRP" value="1" />
        <label for="SRP">SRP</label>
      </li>
    </ul>
    </fieldset>
  <br>
  <br>

  <fieldset class="group">
    <legend>IT</legend>
    <ul class="checkbox">
      <li>
        <input name="docu[]" type="checkbox" id="SSK" value="1" />
        <label for="SSK">SSK</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="SSW" value="1" />
        <label for="SSW">SSW</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="PM" value="1" />
        <label for="PM">PM</label>
      </li>
      <li>
        <input name="docu[]x" type="checkbox" id="PP" value="1" />
        <label for="PP">PP</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="KP" value="1" />
        <label for="KP">KP</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="DS" value="1" />
        <label for="DS">DS</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="APP" value="1" />
        <label for="APP">APP</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="RE1" value="1" />
        <label for="RE1">Resit Rasmi Bayaran</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="LU2" value="1" />
        <label for="LU2">LU2</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="NPT" value="1" />
        <label for="NPT">NPT</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="SRP" value="1" />
        <label for="SRP">SRP</label>
      </li>
    </ul>
    </fieldset>
  <br>
  <br>
  <fieldset class="group">
    <legend>ANK</legend>
    <ul class="checkbox">
      <li>
        <input name="docu[]" type="checkbox" id="SSK" value="1" />
        <label for="SSK">SSK</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="PM" value="1" />
        <label for="PM">PM</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="PP" value="1" />
        <label for="PP">PP</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="KP" value="1" />
        <label for="KP">KP/label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="DS" value="1" />
        <label for="DS">Dokumen-dokumen Sokongan</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="APP" value="1" />
        <label for="APP">APP</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="RE1" value="1" />
        <label for="RE1">RE1</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="LU2" value="1" />
        <label for="LU2">LU2</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="NPT" value="1" />
        <label for="NPT">NPT</label>
      </li>
      <li>
        <input name="docu[]" type="checkbox" id="SRP" value="1" />
        <label for="SRP">SRP</label>
      </li>
    </ul>
    </fieldset></form>

这里我的代码将STATEMENT 插入数据库:

    $IC2 = $_SESSION['IC2'];
    $BMK81A = $_POST['BMK81A'];
    $BMK81 = $_POST['BMK81'];
    $DL3 = $_POST['DL3'];
    $DL2 = $_POST['DL2'];
    $DL1 = $_POST['DL1'];   
    $SSK = $_POST['SSK'];
    $SSW = $_POST['SSW'];
    $PM = $_POST['PM'];
    $PT = $_POST['PT'];
    $AT = $_POST['AT'];
    $SSA = $_POST['SSA'];
    $BW = $_POST['BW'];
    $DS = $_POST['DS'];
    $APP = $_POST['APP'];
    $RE1 = $_POST['REI'];
    $LU2 = $_POST['LU2'];
    $NPT = $_POST['NPT'];
    $SRP = $_POST['SRP'];
    $KTDP = $_POST['KTDP'];
    $KDP = $_POST['KDP'];
    $USPD = $_POST['USPD'];*/


 $insert_data=mysql_query(" INSERT into nama_doku21 (NO_KPT2,BMK81A, BMK81,DL3,DL2,DL1) VALUES  ('$IC2','$BMK81A','$BMK81','$DL3','$DL2','$DL1') ") or die(mysql_error());

 /*$insert_data1=mysql_query(" INSERT into doku_pemohon (SSK,PM,PP,PT,AT,SSA,BW,DS,APP,RE1,LU2,NPT,SRP,KDP) VALUES ('$SSK','$PM','$PP','$PT','$AT','$SSA','$BW','$DS','$APP','$REI','$LU2','$NPT','$SRP','$KDP') ")
 or die(mysql_error());


  $insert_data2=mysql_query(" INSERT into doku_ibu (SSW,SSK,PM,PP,KP,BW,DS,APP,RE1,LU2,NPT,SRP) VALUES  ('$SSW',' $SSK','$PM','$PP',' $KP','$BW','$DS ','$APP','$REI',' $LU2','$NPT','$SRP') ")
 or die(mysql_error());


 $insert_data3=mysql_query(" INSERT into doku_bapa (SSW,SSK, PM,PP,KP,BW,DS,APP,RE1,LU2,NPT,SRP) VALUES  ('$SSW','$SSK',' $PM','$PP','$KP ','$BW','$DS',' $APP','$REI','$LU2','$NPT','$SRP') ")
 or die(mysql_error());



  $insert_data4=mysql_query(" INSERT into doku_penganjur (SSW,SSK,PM,PP,KP,BW,DS,AAP,RE1,LU2,NPT,SRP,KTDP) VALUES  ('$SSW','$SSK','$PM','$PP','$KP','$BW','$DS','$APP','$REI','$LU2','$NPT','$SRP','$KTDP') ")
 or die(mysql_error());



 $insert_data5=mysql_query(" INSERT into doku_adikberadik (SSK,PM,PP,KP,DS,APP,REI,LU2,NPT,SRP) VALUES  ('$SSK','$PM','$PP','$KP','$DS','$BW','$APP','$REI','$LU2','$NPT','$SRP') ")
 or die(mysql_error());



 $insert_data6=mysql_query(" INSERT into doku_suami (SSW,SSK,PM,PP,KP,DS,APP,RE1,LU2,NPT,SRP) VALUES    ('$SSW''$SSK','$PM','$PP','$KP','$DS','$APP','$REI','$LU2','$NPT','$SRP' ) ")
 or die(mysql_error()); 



 $insert_data7=mysql_query(" INSERT into doku_isteri (PM,PP,PT,AT,DS,APP,RE1,LU2,NPT,SRP) VALUES    ('$SSK','$PP','$PT','$AT','$DS','$APP','$RE1','$LU2','$NPT','$SRP') ")
 or die(mysql_error()); 




$insert_data8=mysql_query(" INSERT into doku_anak(SSK,PP,PT,AT,DS,APP,RE1,LU2,NPT,SRP) VALUES  ('$SSK','$PP','$PT','$AT','$DS','$APP','$RE1','$LU2','$NPT','$SRP') ")
 or die(mysql_error()); 

1 个答案:

答案 0 :(得分:0)

我猜您应该更改表单中的输入名称。 例如:

<input name="docu[]" type="checkbox" value="BMK81A"/> <label for="BMK81A">BMK81A</label><br>

应该是:

<input name="BMK81A" type="checkbox" value="BMK81A"/> <label for="BMK81A">BMK81A</label><br>

,否则

$BMK81A = $_POST['BMK81A'];

仍然是空的,或者我在这里错过了一些东西。