title: insert one or more rows from an HTML form
body: <p>I realise that this may be a duplicate question but I can't seem to find the right answer.</p>
  
  <p>I'm trying to insert multiple rows into a MySQL table but, at the moment, all I'm doing is inserting the same data multiple times.</p>
  
  <p>The table is called 'tblRoomsBooked' and the fields are <code>bookingNumber, roomID, roomRate</code> and <code>depositRate</code>. The table has it's own unique, primary key, <code>roomBookedID</code> which auto-increments.</p>
  
  <p>We have an HTML form for booking rooms that we hire out. There are four rooms that can be hired in any combination. Each room has its own ID, hire cost and deposit amount required. So, for example, if one room was booked with a deposit, there should be one record inserted consisting of the booking number, the room's ID, the room's cost and its deposit. If three rooms were to be hired, there should be three separate records inserted, each record would hold the room ID, room cost and deposit of each room booked but all the rooms booked at the one time would have the same booking number.</p>
  
  <p>The SQL code is:</p>
  
  <pre><code>$bookingNumber = ($_POST['bookingNumber']);
  $roomID = ($_POST['roomID']);
  $roomRate = ($_POST['roomRate']);
  $depositRate = ($_POST['depositRate']);
  
  $RoomsBooked = "INSERT INTO tblRoomsBooked (bookingNumber, roomID, roomRate, depositRate) VALUES ('$bookingNumber', '$roomID', '$roomRate', '$depositRate')";
  </code></pre>
  
  <p>If I use $RoomsBooked = <code>"INSERT INTO tblRoomsBooked (bookingNumber, roomID, roomRate, depositRate) VALUES ('$bookingNumber', '$roomID', '$roomRate', '$depositRate'), ('$bookingNumber', '$roomID', '$roomRate', '$depositRate'). ('$bookingNumber', '$roomID', '$roomRate', '$depositRate'), ('$bookingNumber', '$roomID', '$roomRate', '$depositRate')";</code> as I read elsewhere here, it just creates four rows of the same data, regardless of the combination of rooms selected.</p>
  
  <p>The rooms are selected by checkboxes...</p>
  
  <pre><code>&lt;input type="checkbox" class="checkboxMargins" id="meetingRoom" name="roomID" value="1" onClick="Check();"&gt;
  &lt;input type="checkbox" class="checkboxMargins" id="library" name="roomID" value="2" onClick="Check();"&gt;
  &lt;input type="checkbox" class="checkboxMargins" id="jajRoom" name="roomID" value="3" onClick="Check();"&gt;
  &lt;input type="checkbox" class="checkboxMargins" id="annex" name="roomID" value="4" onClick="Check();"&gt;
  </code></pre>
  
  <p>When a checkbox is selected, some JQuery scripting by <a href="https://stackoverflow.com/users/1978210/jonojames">JonoJames</a> which can be found here <a href="https://stackoverflow.com/questions/58941437/output-data-from-mysql-table-into-html-form-depending-on-user-choice">Output Data From MYSQL...</a> is used to fill hidden input boxes for the room costs.</p>
  
  <p>I've tried using <code>name="roomID[]</code> but this throws an error regarding arrays and not liking the <code>INSERT</code> statement.</p>
  
  <p>All this works perfectly for booking one room, it's just if more than one is booked that I can't make work.</p>
  
  <p>I think I need to use <code>for</code> or <code>foreach</code> but the examples on here don't really show how to take the data from the form to insert it into the table.</p>
  
  <p>What I need to know is, if <code>for</code> or <code>foreach</code> is the way to go, what to do and how to use it. If not, what do I need to do?</p>