首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法从数据库值表单php中插入多个值

无法从数据库值表单php中插入多个值
EN

Stack Overflow用户
提问于 2016-01-30 14:23:56
回答 3查看 55关注 0票数 0

这是我得到的错误:

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

代码语言:javascript
复制
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

表格:

代码语言:javascript
复制
 <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:

代码语言:javascript
复制
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>';
}

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

代码语言:javascript
复制
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上制作它。我对任何解决办法都很感兴趣。非常感谢。

EN

回答 3

Stack Overflow用户

发布于 2016-01-30 14:28:47

第一件事:

代码语言:javascript
复制
if(! $_GET['no_siri']) {
  $no_siri = $_GET['no_siri'];
}

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

票数 0
EN

Stack Overflow用户

发布于 2016-01-30 16:20:05

试着包装:

代码语言:javascript
复制
if(isset($_GET['no_siri'])){
      $no_siri = $_GET['no_siri'];
}
票数 0
EN

Stack Overflow用户

发布于 2016-01-31 01:18:49

较短:

代码语言:javascript
复制
$no_siri = @$_GET['no_siri'];

它为$no_siri留下了值或null@防止错误消息。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35102906

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档