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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.