I have run into a problem... I have a pair of checkboxes that I have named and numbered. I need to get the checkboxes marked and insert them into my database. Here is how I am creating the checkboxes:
<div class="check"><input type="checkbox" name="acharge1" value="1"> <span style="color: #0C0">$$</span><input type="checkbox" name="amenities1" value="1">Amenity 1</div>
<div class="check"><input type="checkbox" name="acharge2" value="1"> <span style="color: #0C0">$$</span><input type="checkbox" name="amenities2" value="1">Amenity 2</div>
<div class="check"><input type="checkbox" name="acharge3" value="1"> <span style="color: #0C0">$$</span><input type="checkbox" name="amenities3" value="1">Amenity 3</div>
<div class="check"><input type="checkbox" name="acharge4" value="1"> <span style="color: #0C0">$$</span><input type="checkbox" name="amenities4" value="1">Amenity 4</div>
Some of these will be checked and some wont. Also they will not always be checked in pairs, but I have to upload them in pairs to my database. So in other words: acharge1 and amenities1 will not be checked but acharge2 and amenities2 will be. So I tried a foreach loop and that did not work. I also tried a while loop, but I did not know what to check. So this is what I have now:
$aa = 1;
echo "Amenity: ".$_POST['amenities'.$aa];
$aa++;
while(isset($_POST['amenities'.$aa])){
$amen = $_POST['amenities'.$aa];
if(isset($_POST['acharge'.$aa])){
$acharge = $_POST['acharge'.$aa];
}else{
$acharge = "0";
}
echo "Amen: ". $amen." charge: ".$acharge;
mysql_query("INSERT INTO hotel_amenities (amenity_code, hotel_id, charge) VALUES ('$amen','$hotel_id','$acharge')") or die(mysql_error());
echo $aa;
$aa++;
}
But as you can see this does not work, because if amenities1 is not checked it will not do the while loop through the others. Anyway ANY help on how I can achieve this would be greatly appreciated!
EDIT** This is the concept, so as you can see that sometimes they money box will be checked with the amenity and sometimes it will not. http://www.cancunelitetravel.com/ale/Capture.PNG