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