試圖獲得此選項以允許選擇多於1個複選框。foreach只插入一條記錄?不能看到錯誤?
表
<fieldset>
<legend>Rooms</legend>
<ol>
<li>
<label for =youthCafe>Youth Cafe</label>
<input type="checkbox" name="roomid[]" value="1" ><br>
<label for =inkwellMain>Inkwell Main</label>
<input type="checkbox" name="roomid[]" value="2"><br>
<label for =inkwellSmall>Inkwell Small</label>
<input type="checkbox" name="roomid[]" value="3"><br>
<label for =kitchen>Kitchen</label>
<input type="checkbox" name="roomid[]" value="4"><br>
<label for =outsideCatering>Outside Catering</label>
<input type="checkbox" name="roomid[]" value="5"><br>
</li>
</ol>
</fieldset>
PHP
mysql_select_db('eydg');
$query = "insert into orders (customerNo)
values ($customerNo)";
$result = mysql_query($query);
$query = "select * from orders where customerNo = '$customerNo'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$bookingNo= $row['bookingNo'];
if (isset($_POST['roomid'])){
foreach($_POST['roomid'] as $value){
$query = "insert into bookings (bookingNo,roomNo)
values ('$bookingNo','$value')";
$result = mysql_query($query);
}
}
目前只會讓1選擇要添加到數據庫中。它們都是獨立工作的,但如果選擇多於1,則只插入第一個。
真的不能看到它有什麼問題。
謝謝
顯示更多php代碼 –
@Feroz我添加了一點點,所以你有更好的範圍。 – FallingStar
正如@MakKrnic提到的那樣請提供'var_dump($ _ POST)'或'var_dump($ _ POST ['roomid'])的輸出' – Basic