hartyz Posted March 28, 2012 Share Posted March 28, 2012 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 https://forums.phpfreaks.com/topic/259851-arraysession-problem/ Share on other sites More sharing options...
Drummin Posted March 28, 2012 Share Posted March 28, 2012 Session setting needs to be done before output or ANYTHING is sent to browser, eg. <html> etc. Restructure page. Link to comment https://forums.phpfreaks.com/topic/259851-arraysession-problem/#findComment-1331778 Share on other sites More sharing options...
AyKay47 Posted March 28, 2012 Share Posted March 28, 2012 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. Link to comment https://forums.phpfreaks.com/topic/259851-arraysession-problem/#findComment-1331836 Share on other sites More sharing options...
Vel Posted March 28, 2012 Share Posted March 28, 2012 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 https://forums.phpfreaks.com/topic/259851-arraysession-problem/#findComment-1332004 Share on other sites More sharing options...
hartyz Posted March 29, 2012 Author Share Posted March 29, 2012 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 https://forums.phpfreaks.com/topic/259851-arraysession-problem/#findComment-1332157 Share on other sites More sharing options...
AyKay47 Posted March 29, 2012 Share Posted March 29, 2012 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 https://forums.phpfreaks.com/topic/259851-arraysession-problem/#findComment-1332170 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.