simon551 Posted July 12, 2007 Share Posted July 12, 2007 Hi, I'm trying to insert multiple entries via a dynamic repeated region form. This is the form: <input name="ticketDetId[<?php echo $row_rsTicketDets['itineraryDetId'] ?>]" type="text" id="ticketDetId" size="8" value="<?php echo $row_rsTicketDets['itineraryDetId'].'.' .$row_rsTicketDets['projId'];?>"/> <input name="amtUS[<?php echo $row_rsTicketDets['itineraryDetId'] ?>]" type="text" id="amtUS" size="8" value=""/> I think I may be close but far away. As you can see I am storing values in an array. The hidden field values seem to be working right. But the text field values I'm having a hard time pulling out. This is my script: foreach ($_POST['ticketDetId'] as $check){ $values = explode(".", $check); $ticketDetid = $values[0]; $projId = $values[1]; foreach ($_POST['amtUS'] as $value) { $amt = $value[0]; } $insertSQL = "INSERT INTO testing (ticketDetId, projId, amtUS) VALUES ('$ticketDetid', '$projId', '$amt')"; echo $insertSQL; } If I have two entries on my page, each with a itineraryDetId and a projId, I go ahead and enter the amounts of 3750 and 2110 in the field and POST. Then I echo out the query result for testing: INSERT INTO testing (ticketDetId, projId, amtUS) VALUES ('7', '461', '2')INSERT INTO testing (ticketDetId, projId, amtUS) VALUES ('8', '637', '2') You might be able to tell that I'm kind of lost about how to pull the values out from the text box. another thing I've tried, just to see what's happening with the submit is to put in a print_r ($_POST); statement in the posting script. This is the result of that: Array ( [ticketDetId] => Array ( [7] => 7.461 [8] => 8.637 ) [amtUS] => Array ( [7] => 3750 [8] => 2110 ) Any help is appreciated. -s Quote Link to comment https://forums.phpfreaks.com/topic/59664-solved-trying-to-do-a-multiple-inserts-from-dynamic-form-w-data-entry/ Share on other sites More sharing options...
sasa Posted July 12, 2007 Share Posted July 12, 2007 try foreach ($_POST['ticketDetId'] as $key => $check){ $values = explode(".", $check); $ticketDetid = $values[0]; $projId = $values[1]; $amt = $_POST['amtUS'][$key] //some check $amt }[code] [/code] Quote Link to comment https://forums.phpfreaks.com/topic/59664-solved-trying-to-do-a-multiple-inserts-from-dynamic-form-w-data-entry/#findComment-296537 Share on other sites More sharing options...
simon551 Posted July 12, 2007 Author Share Posted July 12, 2007 print_r ($_POST); foreach ($_POST['ticketDetId'] as $check){ $values = explode(".", $check); $ticketDetid = $values[0]; $projId = $values[1]; $amt = $_POST['amtUS'][$key]; $insertSQL = "INSERT INTO testing (ticketDetId, projId, amtUS) VALUES ('$ticketDetid', '$projId', '$amt')"; echo $insertSQL; } returns: Array ( [ticketDetId] => Array ( [7] => 7.461 [8] => 8.637 ) [amtUS] => Array ( [7] => 3750 [8] => 2110 ) [MM_insert] => form1 [submit] => save ) INSERT INTO testing (ticketDetId, projId, amtUS) VALUES ('7', '461', '')INSERT INTO testing (ticketDetId, projId, amtUS) VALUES ('8', '637', '') Quote Link to comment https://forums.phpfreaks.com/topic/59664-solved-trying-to-do-a-multiple-inserts-from-dynamic-form-w-data-entry/#findComment-296583 Share on other sites More sharing options...
sasa Posted July 12, 2007 Share Posted July 12, 2007 2nd line of your code must be foreach ($_POST['ticketDetId'] as $key => $check){ don't forget key Quote Link to comment https://forums.phpfreaks.com/topic/59664-solved-trying-to-do-a-multiple-inserts-from-dynamic-form-w-data-entry/#findComment-296592 Share on other sites More sharing options...
simon551 Posted July 12, 2007 Author Share Posted July 12, 2007 awesome! Thank you sir! Quote Link to comment https://forums.phpfreaks.com/topic/59664-solved-trying-to-do-a-multiple-inserts-from-dynamic-form-w-data-entry/#findComment-296596 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.