Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Multiple entries to database


Go to End


1127 Views

Avatar
Skullies

Community Member, 19 Posts

20 September 2016 at 6:47pm

Edited: 20/09/2016 7:07pm

Good day all
Im working on a small project where i need to be able to send multiple values to the database.
Basicly the user can select as much "products" as they want and it needs to save the "products" to the database.

	$i = 0;
		  foreach ($_POST['ItemID'] as $x => $y ) {
			$order = itempurchased::create();
				$order->warranty = "$warranty[$i]";
				$order->itemID = "$itemID[$i]";
				$order->amount = "$amount[$i]";
				$order->LampType = "$LampType[$i]";
				$order->ItemModel = "$ItemModel[$i]";
				$order->TotalPP = "$TotalPP[$i]";
				$order->FinalTotal = "$FinalTotal";
				$order->ProductID = "$productID";
			$order->write();
			return $this->order; 
			$i++;
		  } 

Any suggestions would help a lot
Thanks in advance

Edit: I Found my stupid mistake... i was not suppost to add the return $this->order;