Jump to content

Array/Session problem


hartyz

Recommended Posts

I am trying to send some arrays to another page using sessions. The first array I send works fine when I simply print the array on the next page but the second and third arrays are not being created.

 

Code

<?php

				require("dbconn.php");
				$query = mysql_query("SELECT username, idcustomers FROM customers
				WHERE username='$customeruser' ");

					if (!$query) {
					die('Invalid query: ' . mysql_error());}

				$row = mysql_fetch_assoc($query);	
				echo $row['username'];
				$id=$row['idcustomers']; 
				echo $id;

				$productquery = mysql_query("SELECT productid, price1, price2, price3, price1_type, price2_type, price3_type, prod_name, price_det FROM  product_pricing
				WHERE idcustomers='" . mysql_real_escape_string($id) . "' ORDER BY productid");

					if (!$productquery) {
					die('Invalid query: ' . mysql_error());}


					$counter = 1;
				$itemcode_array = array();
			while ($row = mysql_fetch_assoc($productquery)) {



			?>
			<tr class="ordertable">
			<td class="table_item" name="itemcode<?php echo $counter;?>"><?php echo $row['productid']; ?></td><?php $itemcode_send = $row['productid']; array_push($itemcode_array, $itemcode_send); ?>
			<td class="table_name" name="prodname<?php echo $counter;?>"><?php echo $row['prod_name']; ?></td><?php $prod_name_send = $row['prod_name']; array_push($prodname_array, $prod_name_send); ?>
			<td class="table_pdet" name="prod_det<?php echo $counter;?>"><?php echo $row['price_det']; ?></td><?php $price_det_send = $row['price_det']; array_push($pricedet_array, $price_det_send); ?>
			<td class="table_price" name="price1<?php echo $counter;?>"><?php echo $row['price1_type']; ?> $<?php echo $row['price1']; ?></td>
			<td class="table_quant" name="quant1"><input type="text" name="quant1<?php echo $counter;?>" size="4" /></td>
			<td class="table_price" name="price2<?php echo $counter;?>"><?php echo $row['price2_type']; ?> $<?php echo $row['price2']; ?></td>
			<td class="table_quant" name="quant2"><input type="text" name="quant2<?php echo $counter;?>" size="4" /></td>
			<td class="table_price" name="price3<?php echo $counter;?>"><?php echo $row['price3_type']; ?> $<?php echo $row['price3']; ?></td>
			<td class="table_quant" name="quant3"><input type="text" name="quant2<?php echo $counter;?>" size="4" /></td>
			<td class="table_note" name="notes"><input type="text" name="note<?php echo $counter;?>" size="28" /></td>
			</tr>

			<?php
				($counter++);
				} ?>
			<?php mysql_close($dbConn); ?>

		</table> 
		<p><input type="submit" name="submit" value="Confirm" /> <input type="reset" /></p>
				</form>


		<?php print_r($prodname_array);

		$_SESSION["itemcode"] = $itemcode_array;
		 $_SESSION["prodname"] = $prodname_array;
		 $_SESSION["pricedet"] = $pricedet_array; ?>

 

There is some redundant and error testing code in there.

 

The problem is $prodname_array; and $pricedet_array; are not being created even though $itemcode_array which is created the same way works fine. All values from the database are being displayed correctly  (eg $row['prod_name'];).

Link to comment
Share on other sites

Session setting needs to be done before output or ANYTHING is sent to browser, eg. <html> etc.  Restructure page.

Not true, you only need to start the session before sending headers. You can set session data after headers have been sent.

Link to comment
Share on other sites

Arrays need to be declared before you can push values onto them.

You define the first array $itemcode_array = array(); but not the other two.

 

I cant believe I missed that, thank you and sorry for wasting your time.

 

 

Link to comment
Share on other sites

Arrays need to be declared before you can push values onto them.

You define the first array $itemcode_array = array(); but not the other two.

 

I cant believe I missed that, thank you and sorry for wasting your time.

Not a problem, glad it's sorted.

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.