在这里,我有一些案例,我认为这对我来说是独一无二的。 这个问题,我想循环一些标签 3次。循环是工作,但当它输入到数据库... 只有一个循环有效。
这里有截图,
<td>
<label for="baris">Baris</label>
<select name="baris">
<option value="">--</option>
<?php
for ($i2=A; $i2 < F; $i2++) {
echo "<option name='".$i2."'>".$i2."</option>";
}
?>
</select>
</td>
<td>
<label for="kolom">Kolom</label>
<select name="kolom">
<?php
for ($i3=1; $i3 <= 10; $i3++) {
echo '<option name="'.$i3.'">'.$i3.'</option>';
}
?>
</select>
</td>
此输入数据库的代码
<?php
if(isset($_POST['masukan'])){
$nama = htmlspecialchars($_POST['nama']);
$email = htmlspecialchars($_POST['email']);
$jk = htmlspecialchars($_POST['jk']);
$notlp = htmlspecialchars($_POST['notlp']);
$queryinput = mysqli_query($link, "UPDATE tb_customer
SET nama='$nama',
email='$email',
notlp='$notlp',
jk='$jk'
WHERE id_cust='$id_cust1'
");
$querytampil = mysqli_query($link, "SELECT * FROM tb_customer WHERE id_cust ORDER by id_cust desc limit 1");
$dcus = mysqli_fetch_assoc($querytampil);
$id_cust = $dcus['id_cust'];
$querytampil2 = mysqli_query($link, "SELECT max(num_ticket)AS num FROM tb_ticket");
$dnumti = mysqli_fetch_assoc($querytampil2);
$num_ticket = $dnumti['num'];
$hasil = $num_ticket + 1;
for ($i5= 1; $i5 <= $p; $i5++) {
$baris = htmlspecialchars($_POST['baris']);
$kolom = htmlspecialchars($_POST['kolom']);
if($queryinput){
$id_flight = $data['id_flight'];
$queryinput2 = mysqli_query($link, "INSERT INTO tb_ticket VALUES('','$id_cust','$id_flight','$hasil','','','','','$id_dest','$id_ori', '$baris', '$kolom')");
if ($queryinput2) {
$querytampil3 = mysqli_query($link, "SELECT * FROM tb_ticket order by num_ticket desc limit 1");
$dtick = mysqli_fetch_assoc($querytampil3);
$nt = $dtick['num_ticket'];
echo "<script>alert('Succes.')</script>";
echo '<script>window.location="pembayaran.php?num_ticket='.$nt.'&&id_cust='.$id_cust.'"</script>';
}else{
echo "<script>alert('Your data cannot send.')</script>";
}
}else{
echo "<script>alert('Your data cannot send, please check your input data.')</script>";
}
}
}
?>
Bad engslish sorry *
答案 0 :(得分:0)
如果我说得对;这是因为你没有将你的html变量设置为数组。
您需要进行的第一项更改位于您的视图页面中。
<select name="baris">
- &gt; <select name="baris[]">
<select name="kolom">
- &gt; <select name="kolom[]">
这会将您的$_POST['baris']
和$_POST['kolom']
设置为数组。
因为你已经在循环......
for ($i5= 1; $i5 <= $p; $i5++) {
$baris = htmlspecialchars($_POST['baris']);
$kolom = htmlspecialchars($_POST['kolom']);
这个东西现在需要访问相关的数组......并且变成......
for ($i5= 1; $i5 <= $p; $i5++) {
$baris = htmlspecialchars($_POST['baris'][$i5]);
$kolom = htmlspecialchars($_POST['kolom'][$i5]);