繁体   English   中英

无法从数据库值形式php插入多个值

[英]Cannot insert multiple value from database value form php

这是我得到的错误:

注意:未定义索引:第4行的C:\\ xampp \\ htdocs \\ PTG Sistem \\ penyata.php中的no_siri注意:未定义索引:第6行的C:\\ xampp \\ htdocs \\ PTG Sistem \\ penyata.php中的agihan

INSERT INTO penyata (no_siri, tarikh, penerangan, jumlah_bayaran)
     VALUES
     ('','2016-01-30 21:57:08','Agihan keuntungan adalah sebanyak %','720')

注意:未定义的索引:第23行的C:\\ xampp \\ htdocs \\ PTG Sistem \\ penyata.php中的1


形成:

 <form method="get" action="penyata.php">
      <div class="panel-body">
      <table class="table table-striped table-hover">
                    <thead>
                    <tr>

                        <th></th>
                        <th>No Siri</th>
                        <th>Tarikh</th>
                        <th>Nama</th>
                        <th>Bank</th>
                        <th>Akaun Bank</th>
                        <th>Lot</th>
                        <th>Agihan</th>
                        <th>Bayaran</th>

                    </tr>
                    </thead>
                    <tbody>';


                        while($rows_client = mysql_fetch_array($bayar_client)){

                            $total_bayar = $rows_client['lot'] * ($bayaran /100);

               echo '<tr>

                        <td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="'.$i++.'" /required></td>
                        <td><input name="no_siri[]" type="text" id="no_siri[]" value="'.$rows_client['no_siri'].'" /disabled></td>
                        <td>'.$rows_client['hari'].'/'.$rows_client['bulan'].'/'.$rows_client['tahun'].'</td>
                        <td>'.$rows_client['nama'].'</td>
                        <td>'.$rows_client['nama_bank'].'</td>
                        <td>'.$rows_client['akaun_bank'].'</td>
                        <td>RM'.$rows_client['lot'].'</td>
                        <td><input name="agihan[]" type="text" id="agihan[]" value="'.$bayaran.'" /disabled>%</td>
                        <td>RM <input name="jumlah_bayaran[]" type="text" id="jumlah_bayaran[]" value="'.$total_bayar.'"></td>

                    </tr>';
                        }
                echo '
                        <button type="submit" class="btn btn-info" name="simpan">
                            <i class="fa fa-database"></i>
                        </button>
                        &nbsp;
                        <button class="btn btn-info" onClick="myFunction()" title="Cetak">
                            <i class="fa fa-print"></i>
                        </button>

                        <script>
                            function myFunction() {
                                    window.print();
                            }
                        </script>



                    </tbody>
                    </form>

PHP:

include("dbconn.php");

$no_siri = $_GET['no_siri'];
$agihan = $_GET['agihan'];
date_default_timezone_set('Asia/Kuala_Lumpur');
$tarikh[] = date('Y-m-d H:i:s', time());
$penerangan[] = "Agihan keuntungan adalah sebanyak ".$agihan."%";
$jumlah_bayaran = $_GET['jumlah_bayaran'];

$add_penyata = "INSERT INTO penyata (no_siri, tarikh, penerangan, jumlah_bayaran) VALUES";

$query_parts = array();
foreach($_GET['checkbox'] as $i){
    //for($x=0; $x<count($i); $x++){
        $query_parts[] = "('{$no_siri[$i]}','{$tarikh[$i]}','{$penerangan[$i]}','{$jumlah_bayaran[$i]}')";
    //}
    echo $add_penyata .= implode(',', $query_parts);
}               
//$result = mysql_query($add_penyata);

//echo $add_penyata;

if($result){
    echo '<script type="text/javascript">window.alert("Rekod Berjaya Disimpan.") </script>';
    echo "<script language='JavaScript'>window.location ='akaun.php'</script>";
}
else{
    echo '<script type="text/javascript">window.alert("Ralat!!!!.") </script>';
}

我想从表单插入多个数据,就像

INSERT INTO `penyata`(`id`, `no_siri`, `tarikh`, `penerangan`, `jumlah_bayaran`)
     VALUES
     ([value-1],[value-2],[value-3],[value-4],[value-5]),
     ([value-1],[value-2],[value-3],[value-4],[value-5]),
     and more....

但我不知道如何使它在PHP上。 我很喜欢任何解决方案。 非常感谢。

首先要做的是:

if(! $_GET['no_siri']) {
  $no_siri = $_GET['no_siri'];
}

首先,您必须检查值是否存在。

尝试包装:

if(isset($_GET['no_siri'])){
      $no_siri = $_GET['no_siri'];
}

更短:

$no_siri = @$_GET['no_siri'];

它将$no_siri为value或null @防止出现错误信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM