捕获数组值使用PHP的动态输入字段

时间:2015-12-07 19:06:56

标签: php mysql

我以表格的形式输入。

例如:

  

没有|时间|日(自动生成)|

     

无自动生成|时间自动生成|活动输入表格   |

示例php代码生成表。

<form enctype="multipart/form-data" action="input_jadual.php" method="post">
<table id="example" class="table table-striped table-bordered" width="100%" cellspacing="0">
            <thead>
            <tr>
                <th width="10">No</th>
                <th width="60"><center>Waktu</center></th>
<?php
$begin = new DateTime($ttl1);
$end = new DateTime($ttl2);
$end = $end->modify( '+1 day' );
$interval = new DateInterval('P1D');
$daterange = new DatePeriod($begin, $interval ,$end);
$dayList = array(
    'Sunday' => 'Minggu',
    'Monday' => 'Senin',
    'Tuesday' => 'Selasa',
    'Wednesday' => 'Rabu',
    'Thursday' => 'Kamis',
    'Friday' => 'Jumat',
    'Saturday' => 'Sabtu'
);
foreach($daterange as $date){
    $tgl=$date->format("d-m-Y");
    $hariss = date('l', strtotime($tgl));
    $haris=$dayList[$hariss];
    if ($haris=='Minggu'){
        $warna='red';
        $dis='disabled';
     }else{
        $warna='';
        $dis='';
     }
    ?>
<th><center><input type="hidden" name="hari[]" value="<?php echo $haris; ?>"/><input type="hidden" name="tgl[]" value="<?php echo $tgl; ?>"/><font color="<?php echo $warna; ?>"><?php echo $haris; ?><br><?php echo $tgl; ?></font></center></th>
<?php  } ?>
            </tr>
            </thead>
            <tbody>
<?php $nos=1; $arrlength = count($waktus); for($x = 0; $x < $arrlength; $x++) { ?>
<?php if ($waktus[$x]=='12.00-13.00'){
                        ?>
                        <tr disabled>
                            <td class="data" align="center"><?php echo $nos;?></td>
                            <td class="data" align="center"><input type="hidden" name="waktu[]" value="<?php echo $waktus[$x];?>"/><?php echo $waktus[$x];?></td>
                            <?php $no=1; for($i = 0; $i < (is_numeric($fields)?$fields:1); $i++) { ?>
                            <td class="data" align="center">
                            <i>Istirahat, Sholat & Makan</i>
                            <?php } ?> 
                        </tr>
                        <?php } elseif ($waktus[$x]=='10.15-10.30'){
                        ?>
                        <tr disabled>
                            <td class="data" align="center"><?php echo $nos;?></td>
                            <td class="data" align="center"><input type="hidden" name="waktu[]" value="<?php echo $waktus[$x];?>"/><?php echo $waktus[$x];?></td>
                            <?php $no=1; for($i = 0; $i < (is_numeric($fields)?$fields:1); $i++) { ?>
                            <td class="data" align="center">
                            <i>Coffee Break</i>
                            <?php } ?> 
                        </tr>
                        <?php } elseif ($waktus[$x]=='15.15-15.45'){
                        ?>
                        <tr disabled>
                            <td class="data" align="center"><?php echo $nos;?></td>
                            <td class="data" align="center"><input type="hidden" name="waktu[]" value="<?php echo $waktus[$x];?>"/><?php echo $waktus[$x];?></td>
                            <?php $no=1; for($i = 0; $i < (is_numeric($fields)?$fields:1); $i++) { ?>
                            <td class="data" align="center">
                            <i>Coffee Break</i>
                            <?php } ?> 
                        </tr>
                        <?php } elseif ($waktus[$x]=='18.00-19.00'){
                        ?>
                        <tr disabled>
                            <td class="data" align="center"><?php echo $nos;?></td>
                            <td class="data" align="center"><input type="hidden" name="waktu[]" value="<?php echo $waktus[$x];?>"/><?php echo $waktus[$x];?></td>
                            <?php $no=1; for($i = 0; $i < (is_numeric($fields)?$fields:1); $i++) { ?>
                            <td class="data" align="center">
                            <i>Istirahat, Sholat & Makan</i>
                            <?php } ?> 
                        </tr>
<?php
     }else{
?>
<tr>
<td class="data" align="center"><?php echo $nos;?></td>
                <td class="data" align="center"><input type="hidden" name="waktu[]" value="<?php echo $waktus[$x];?>"/><?php echo $waktus[$x];?></td>
                <?php $no=1; for($i = 0; $i < (is_numeric($fields)?$fields:1); $i++) { ?>
                <td class="data" align="center">
        <input list="modul" name="modul[]" style="border:none" placeholder="Pilih Modul">
          <datalist id="modul">
          <?php include 'include/conn.php';
                $nama_pelatihan=$_POST['nama_pelatihan'];
                $tampil1=mysql_db_query(@$db,"select * from modul where nama_pelatihan='$nama_pelatihan'",@$koneksi);   
                while ($row=mysql_fetch_array($tampil1))
                    {
                    $nama_modul=$row['nama_modul'];
                    $jp=$row['jp'];
                  ?>
            <option value="<?php echo $nama_modul ?> (<?php echo $jp ?>JP)">
                    <?php } ?>
          </datalist>
        <input list="widyaiswara" name="widyaiswara[]" style="border:none" placeholder="Pilih Widyaiswara">
          <datalist id="widyaiswara">
          <?php include 'include/conn.php';
                $tampil2=mysql_db_query(@$db,"select * from data_pokok",@$koneksi); 
                while ($row=mysql_fetch_array($tampil2))
                    {
                    $nama=$row['nama'];
                  ?>
            <option value="<?php echo $nama ?>">
                    <?php } ?>
          </datalist>
                <?php } ?> 
</tr>
<?php
     }
    ?>

<?php $nos++; } ?>
<input type="hidden" name="code" value="<?php echo $code ?>"/>
<input type="hidden" name="bidang_diklat" value="<?php echo $bidang_diklat; ?>"/>
<input type="hidden" name="nama_pelatihan" value="<?php echo $nama_pelatihan ?>"/>
<input type="hidden" name="ttl1" value="<?php echo $ttl1 ?>"/>
<input type="hidden" name="ttl2" value="<?php echo $ttl2 ?>"/>
<input type="hidden" name="status" value="draft"/>
</tbody>
</table>
<input type="submit" name="simpan" title="Simpan" value="S I M P A N" class="btn btn-success btn-block btn-lg bayang" onclick="cekForm()">
</form>

php代码插入:

<?php 
    include "include/conn.php";
    $tanggal;
    if (isset($_POST['simpan']))//periksa apakah user telah menekan submit, dengan menggunakan parameter setingan isi
    {
    $bidang_diklat=$_POST['bidang_diklat'];
    $nama_pelatihan=$_POST['nama_pelatihan'];
    $ttl1=$_POST['ttl1'];
    $ttl2=$_POST['ttl2'];
    $status=$_POST['status'];
    $code=$_POST['code'];

    $jam=$_POST['jam'];
    $hari=$_POST['hari'];
    $tgl=$_POST['tgl'];
    $modul=$_POST['modul'];
    $widyaiswara=$_POST['widyaiswara'];

    //periksa jika data yang dimasukan belum lengkap
        if (empty($bidang_diklat))
            {
                echo "<script> document.location.href='index.php?page=Jadual&status=draft&error=8'</script>";
            }
            $upload=mysql_db_query($db,"INSERT INTO jadual (bidang_diklat,nama_pelatihan,ttl1,ttl2,status,code) VALUES('$bidang_diklat','$nama_pelatihan','$ttl1','$ttl2','$status','$code')");
            $upload2=mysql_db_query($db,"INSERT INTO jadual_kegiatan (code,jam,hari,tgl,modul,widyaiswara) VALUES('$code','$jam','$hari','$tgl','$modul','$widyaiswara')");
            echo "<script> document.location.href='index.php?page=Jadual&status=draft'; </script>";
    }
    else
    {
        unset($_POST['simpan']);
    }
    ?>

但不要在mysql中插入。 。 。 请帮助概念&amp;插入的示例代码。

提前谢谢你们! :d

0 个答案:

没有答案