[英]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>
<button class="btn btn-info" onClick="myFunction()" title="Cetak">
<i class="fa fa-print"></i>
</button>
<script>
function myFunction() {
window.print();
}
</script>
</tbody>
</form>
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.