php1 Posted June 13, 2008 Share Posted June 13, 2008 I have a form which pass array as hidden variable to a php script. The value assigned to array is a variable which is from a for loop. my problem is that when i try to take the value frm the second page i got only the value as "atrray". can any body please hepl?? urgent?? i will paste my code here. 1st page(there are codes before this and after this) --------------------------------------------------------------------------------------------------------------------------------------------------------- <?php $cartContent = getCartContent(); $numItem = count($cartContent); $subTotal = 0; for ($i = 0; $i < $numItem; $i++) { extract($cartContent[$i]); //from cartcontent we get pd_* and cat_* values * represents id,price,qty etc $productUrl = "index.php?c=$cat_id&p=$pd_id"; $subTotal += $pd_price * $ct_qty; ?> <tr class="content"> <td width="80" align="center"><a href="<?php echo $productUrl; ?>"><img src="<?php echo $pd_thumbnail; ?>" border="0"></a></td> <td><a href="<?php echo $productUrl; ?>"><?php echo $pd_name; ?></a></td> <td align="right"><?php echo displayAmount($pd_price); ?></td> <td width="75"><input name="txtQty[]" type="text" id="txtQty[]" size="5" value="<?php echo $ct_qty; ?>" class="box" onKeyUp="checkNumber(this);"> <input name="hidCartId[]" type="hidden" value="<?php echo $ct_id; ?>"> <input name="hidProductId[]" type="hidden" value="<?php echo $pd_id; ?>"> </td> <td align="right"><?php echo displayAmount($pd_price * $ct_qty); ?></td> <td width="75" align="center"> <input name="btnDelete" type="button" id="btnDelete" value="Delete" onClick="window.location.href='<?php echo $_SERVER['PHP_SELF'] . "?action=delete&cid=$ct_id"; ?>';" class="box"> </td> </tr> <?php } ?> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 2nd page --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- <?php function updateCart() { $cartId = $_POST['hidCartId']; $productId = $_POST['hidProductId']; $itemQty = $_POST['txtQty']; $numItem = count($itemQty); $numDeleted = 0; $notice = ''; print_r($itemQty); //ouput is array }?> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- urgent any body plaese help. thanks in advance (edited by kenrbnsn to add tags) Quote Link to comment https://forums.phpfreaks.com/topic/110026-array-paases-as-hidden-variable-problem/ Share on other sites More sharing options...
hansford Posted June 13, 2008 Share Posted June 13, 2008 if you're passing an array. example, try <?php if(isset($_POST['array'])){ foreach($_POST['array'] as $key){ echo $key; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/110026-array-paases-as-hidden-variable-problem/#findComment-564581 Share on other sites More sharing options...
php1 Posted June 13, 2008 Author Share Posted June 13, 2008 i tried your code and my $_POST['array'] is not set whethet i assigend everything correctly in 1st page. some serialize() and unserialize() functions are there, whther I have to use that one. i'm sorry i am new to php.. Quote Link to comment https://forums.phpfreaks.com/topic/110026-array-paases-as-hidden-variable-problem/#findComment-564586 Share on other sites More sharing options...
hansford Posted June 13, 2008 Share Posted June 13, 2008 I'm not seeing the form in your code, which is important in the way php will handle the form values. Please post. Quote Link to comment https://forums.phpfreaks.com/topic/110026-array-paases-as-hidden-variable-problem/#findComment-564697 Share on other sites More sharing options...
tapos Posted June 13, 2008 Share Posted June 13, 2008 you can make the $_POST variables as hidden like bellow <?php foreach($_POST as $key => $value) { echo '<input type="hidden" name="'.$key.'" value="'.$value.'">'; } ?> Hope this will help you Quote Link to comment https://forums.phpfreaks.com/topic/110026-array-paases-as-hidden-variable-problem/#findComment-564704 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.