Jump to content

Array Print problem with foreach statment


viper6277

Recommended Posts

Hi All, I have an php script with, what I think is a small array problem....this is a piece of the code.

 

Basically the loop gets data from a form then does an insert of the array into my database, which all woks except for the last field ....part_status...

 

foreach($_POST["part"] as $key=>$val)
{
  $qty = $_POST["qty"][$key];
  $part_status = $_POST["part_status"][$key];

  $data_insert.='("'.$val.'",
                           "'.$qty.'",
                           "'.$part_status.'"),';

   echo "Part Number: $val QTY: $qty Part Status: $part_status<br />\n";
}

//remove last comma
$data_insert=substr($data_insert,0,-1);
$sql_parts="INSERT INTO tbl_service_calls_parts (part_number,qty, part_status) VALUES ".$data_insert.""; 

 

 

this is the result: ....What the hell is that "0" about.... it should say "Part Status" just like the line before it.

 

Part Number: FF3-001-000 QTY: 2 Part Status: Part Used

Part Number: AA2-001-000 QTY: 5 Part Status: 0

 

I'm at a loss, if I drop the "$part_status = $_POST["part_status"][$key];" the script works fine.

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.