Jump to content

[SOLVED] trying to do a multiple inserts from dynamic form w/ data entry


simon551

Recommended Posts

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

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', '')

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.