Hello all, been trying for over a day to get something to work and after searching and searching I could not find what I was looking for. I found people looking to do something similar, but the answers seemed more complicated than I would think they need to be. First off, I'm still horrible at arrays and loops so try not to laugh too hard if my code is waaaayyyy off...haha
I am essentially trying to tie products and quantities to a reservation. The user has the ability to add items to the form. I'm using jquery .clone to create each new item product and quantity form fields. When the user submits the form jquery inputs the values of the cloned fields into 2 hidden text fields called "productsField" and "quantitiesField" The values of these fields look something like value="1,2,2,1,3" depending on how many products were added.
What I want to do is explode both and then enter them into the database. Seems simple enough, but apparently I am not getting it.
I thought something like this would work, but it is not.
if (isset($_POST["reserve_button"])) {
$theReservationID = $_SESSION['createdReservationID'];
$items = explode (",",$_POST['productsField']);
$quantities = explode (",",$_POST['quantitiesField']);
// loop through array
$number = count($items);
for ($i=0; $i<=$number; $i++)
{
// store a single item number and quantity in local variables
$itno = $items[$i];
$quant = $quantities[$i];
if ($items[$i] <> '') {
mysql_query('INSERT INTO reservation_items (reservationID,productID,productQuantity) VALUES($theReservationID,$itno,$quant)');
}
}
}
Any help would be greatly appreciated.
Thanks in advance,
Twitch