Jump to content

Arrays


Schlo_50

Recommended Posts

Hey guys,

 

Im having problems for some reason. Im trying to pass some data from products.php to final.php using sessions. When i view final.php all I can see when I print the results is 'Array'. I then tried to do a foreach() on that, but nothing is outputted then..

 

products.php

$orderid = array();
$quantity = array();

   foreach($_POST['orderid'] as $item => $quantity)
{
	$quantity = $_POST['quantity'][$item];
	if($quantity>0)
	{
		print "Item# ".$item." : Quantity ".$quantity."<br />";	
	}
}
$_SESSION['item'] = $item;
$_SESSION['quan'] = $quantity;

 

final.php

$value = $_SESSION['item'];
$valueb = $_SESSION['quan'];

print "Item# ".$value."<br />";
print "Quantity ".$valueb."";

 

Anyone with any ideas?

 

Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/95581-arrays/
Share on other sites

I shall print my products.php script to help. That whay if there is anything really wrong with it you can point it out.

 

<?php
session_start(); 

include_once('odbc/odbc.php'); 
require_once('operate.php');

// check to see if user is logged in
checkUser();
// get user email, phone number and fax session variable to add to database
sessionSet();

$cust_name = $_SESSION['userName'];
$recordupdate = ""; 

// if 'next' is clicked item numbers & quantities user has picked are displayed, along with a 'Confirm' button to proceed with the next part of the script.
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();

   foreach($_POST['orderid'] as $item => $quantity)
{
	$quantity = $_POST['quantity'][$item];
	if($quantity>0)
	{
		print "Item# ".$item." : Quantity ".$quantity."<br />";	
	}
}
$_SESSION['item'] = $item;
$_SESSION['quan'] = $quantity;


  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>";
   
  }
  
?>
<html>
<head>
<title>none</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<style type="text/css"></style>
</head>
<form name="the_form" id="the_form" method="post" action="?id=products">

<?php
// connect to access database and find the table 'Product1'
$sql2 = odbc_exec($odbc, "SELECT * FROM Product1 ORDER BY CategoryName AND Grouping") or die (odbc_errormsg());

// define variables - use lowercase for variables names
$prevcat = "";


while($row = odbc_fetch_array($sql2))
{
	$category = $row["CategoryName"];
	$productid = $row["ProductId"];
	$productname = $row["ProductName"];
	$price = $row["Price"];
	$type = $row["Type"];
	$habit = $row["Habit"];
	$colour = $row["Colour"];
	$status = $row["Status"];


	// find out if category has changed
	// if so, print it, and it's contents
	if ($category != $prevcat)  {
		echo "<p class='title'><u>{$category}</u></p>"; 
	}

	echo  "
	<p class=main2>
	<strong>{$productname}</strong> - 
	({$colour} 
	{$status} 
	Item#{$productid}) 
	<span class=address1>£{$price} 
	<input name=\"orderid[{$productid}]\" value=\"{$productid}\" type=\"hidden\"/> 
	<input name=\"quantity[{$productid}]\" type=\"text\" size=\"3\" maxlength=\"3\" />
	<input type=\"hidden\" name=\"price[{$productid}]\" value=\"{$price}\"></span></p>
	";

	$prevcat = $category;
}
?>
<hr />
	 <? print $recordupdate; ?>
	 <input name="update" type="submit" value="Review Order" />
	</p>
  </p>
 </div>
</form>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/95581-arrays/#findComment-489311
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.