Jump to content

Passing array data


Schlo_50

Recommended Posts

I have an order form, which displays items for users to select. Once they are finished selecting items they click 'confirm order' which displays a list of the items and quantities orders using the foreach() function. Once the user has verified the order details i'd like for them to click 'submit order' and be taken to final.php where they complete the order.

 

The problem is i can't get the item numbers and quantites to pass from products.php to final.php..I've tried to use sessions but i cant get it to work.

 

if (isset($_POST['update']) && ($_POST['update']==="Review Order")) {

	  //print out the order details and click 'Confirm' to enter details into database
  print "
  <span class=\"title\">Order Details</span><br /><br /><span class=\"main2\">View your order details below. 
  If they are correct click 'Confirm Order' to submit the final order details. We will invoice your account 
  accordingly.</span><br /><br />
  		";
  
  print "<span class=\"main2\"><form name=\"the_forma\" id=\"the_forma\" method=\"post\" action=\"?id=final\"></span>";
  	
  $orderid = array();
  $quantity = array();
  $price = array();

  foreach($_POST['orderid'] as $item => $quantity){

	$quantity = $_POST['quantity'][$item];
	if(strcmp($quantity, "")!=0){

	print "Item# ".$item." : Quantity ".$quantity."<br />";

}
}

  print "<span class=\"main2\"><input type=\"button\" value=\"Back\" onClick=\"history.go(-1)\"></span><br />";	   
  print "<span class=\"main2\"><input name=\"update\" type=\"submit\" value=\"Confirm Order\"></span>";
  print "</form>";
  print "<span class=\"main2\"><hr /></span>";
   
  }

 

Any ideas?

 

Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/95451-passing-array-data/
Share on other sites

you could just build hidden form elements

ie

 

ie

<?php
  foreach($_POST['orderid'] as $item => $quantity)
{
	$quantity = $_POST['quantity'][$item];
	if($quantity>0)
	{
		print "Item# ".$item." : Quantity ".$quantity."<br />";
		print "<input type=\"hidden\" name=\"$item\" value=\"$quantity\">";
	}
}
?>

 

but personally i would use session remember use the session_start(); at the start!

Link to comment
https://forums.phpfreaks.com/topic/95451-passing-array-data/#findComment-488642
Share on other sites

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.