viper6277 Posted September 26, 2007 Share Posted September 26, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/70707-array-print-problem-with-foreach-statment/ Share on other sites More sharing options...
cooldude832 Posted September 26, 2007 Share Posted September 26, 2007 maybe seeing this form might help Quote Link to comment https://forums.phpfreaks.com/topic/70707-array-print-problem-with-foreach-statment/#findComment-355414 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.