Brendan Posted July 11, 2006 Share Posted July 11, 2006 How would i go about using post with an array? For example:$stock_val='stock['.$current_array.']';$sizes_val='sizes['.$current_array.']';print 'Size: <input name="'.$sizes_val.'" style="width:50px;" type="text" value="?">Stock: <input name="'.$stock_val.'" style="width:50px;" type="text" value="?"><br><font style="font-size:10px;">';The name fields work fine, but i can't seem to figure out how to use $_POST for the value field with the array. Quote Link to comment https://forums.phpfreaks.com/topic/14271-array-and-value/ Share on other sites More sharing options...
brown2005 Posted July 11, 2006 Share Posted July 11, 2006 CAN YOU EXPLAIN SOME MORE, WHAT ARE YOU TRYING TODO, GET A RESULT FROM A FORM AS A POST? Quote Link to comment https://forums.phpfreaks.com/topic/14271-array-and-value/#findComment-56073 Share on other sites More sharing options...
ShogunWarrior Posted July 11, 2006 Share Posted July 11, 2006 use [b]serialize[/b] on the array and then when you get the data out of $_POST [b]unserialize[/b] it and it will be an array again. Quote Link to comment https://forums.phpfreaks.com/topic/14271-array-and-value/#findComment-56110 Share on other sites More sharing options...
Brendan Posted July 11, 2006 Author Share Posted July 11, 2006 That doesn't seem to work. For example:while ($i>0) {$current_array+=1;$i-=1;$temp='$sizes['.$current_array.']';$sizes_val=serialize($temp);$sizes_val_final=$_POST['$sizes_val'];$temp2='$stock['.$current_array.']';$stock_val=serialize($temp2);$stock_val_final=$_POST['$stock_val'];$size_fields.='Size: <input name="'.$sizes_val.'" style="width:50px;" type="text" value="'.$sizes_val_final.'">Stock: <input name="'.$stock_val.'" style="width:50px;" type="text" value="'.$stock_val_final.'"><br><font style="font-size:10px;"><p>'.$current_array.'<p>';}print $size_fields;}This doesn't work, and i'm not sure how else to do it. I want to store the value of the text boxes into the sizes[] and stock[] arrays and then return the $_POST information into the value field.Thanks Quote Link to comment https://forums.phpfreaks.com/topic/14271-array-and-value/#findComment-56479 Share on other sites More sharing options...
kenrbnsn Posted July 11, 2006 Share Posted July 11, 2006 I see <input> tags, but no <form> tags. Is this the complete script?Please post the script that generates the form and the script that processes it (if that is a separate script). Please post all code between [b][color=red][nobbc][code]<?php ?>[/code][/nobbc][/color][/b] tags.Ken Quote Link to comment https://forums.phpfreaks.com/topic/14271-array-and-value/#findComment-56498 Share on other sites More sharing options...
Brendan Posted July 11, 2006 Author Share Posted July 11, 2006 see below Quote Link to comment https://forums.phpfreaks.com/topic/14271-array-and-value/#findComment-56503 Share on other sites More sharing options...
kenrbnsn Posted July 11, 2006 Share Posted July 11, 2006 Thanks for posting the code. I modified your post to put all code between [b][nobbc][code][/code][/nobbc][/b] tags.Ken Quote Link to comment https://forums.phpfreaks.com/topic/14271-array-and-value/#findComment-56514 Share on other sites More sharing options...
Brendan Posted July 12, 2006 Author Share Posted July 12, 2006 This is the code that i have so far; i can't seem to output a valid array. You can see where i have the code $q = implode(",", $sizes); and print $q;. This should output 4,2,5, ect. depending on what the user typed into the form, but it displays nothing at all, it's empty. It doesnt seem to be valid outside of the while loop for some reason.[code]<?php include("login.php");$formdisplay="show";$font="#000000";$redf="#DD7171";$font_color=$font;$msg="Use this form to add a product to the inventory.";if (!isset($size_fields)) {$size_fields="";}$pid=$_GET['pid'];<<removed some post and mysql values that were here>>if(($_POST['add_sizes']) or ($_POST['submit'])){if($_POST['add_sizes_amount']<10){$ii=$_POST['add_sizes_amount'];$i=$ii+$current_array;if ($_POST['submit']) {$i-=$ii;}$current_array=0;while ($i>0) {$current_array++;$i--;$temp='sizes'.$current_array;$sizes_val_final=$_POST[$temp];$sizes=array($current_array => $sizes_val_final);$temp2='stock'.$current_array;$stock_val_final=$_POST[$temp2];$stock=array($current_array => $stock_val_final); $size_fields.='Size: <input name="'.$temp.'" style="width:50px;" type="text" value="'.$sizes_val_final.'">Stock: <input name="'.$temp2.'" style="width:50px;" type="text" value="'.$stock_val_final.'"><br><font style="font-size:10px;"><p>'.$current_array.'<p>';}$q = implode(",", $sizes);print $q;print $sizes[1];} else { $msg="Please add no more than 9 fields at a time";}}if($_POST['submit']){if(empty($brandname)){$msg="Please fill in the Brand Name field.";$font_color=$redf;} elseif(empty($product)){$msg="Please fill in the Product field.";$font_color=$redf;} elseif(empty($productid)){$msg="Please fill in the Product ID field.";$font_color=$redf;} elseif(empty($retail)){$msg="Please fill in the Retail Price field.";$font_color=$redf;} elseif(empty($ordercost)){$msg="Please fill in the Order Cost field.";$font_color=$redf;} elseif(empty($color)){$msg="Please fill in the Color field.";$font_color=$redf;} elseif(empty($category)){$msg="Please fill in the Category field.";$font_color=$redf;} else {$sql =mysql_query("INSERT INTO SL_products( `product` , `productid` , `retail` , `ordercost`, `color` , `description` , `category` ) VALUES ('$product' , '$productid' , '$retail' , '$ordercost', '$color' , '$description' , '$category' )"); $sql =mysql_query("INSERT INTO SL_quantity( `product` , `productid` , `retail` , `ordercost`, `color` , `description` , `category` ) VALUES ('$product' , '$productid' , '$retail' , '$ordercost', '$color' , '$description' , '$category' )"); $formdisplay="hide";$msg='Product has been added to the inventory. <a href="http://'.$_SERVER['HTTP_HOST'].'/'.$_SERVER['PHP_SELF'].'>Click here</a> to add another product.';}}include_once ("../layout.php");?> <form action="<?php print $_SERVER['PHP_SELF'].'?pid='.$pid; ?>" method="POST"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <th scope="col"> <table id="formbg" width="100%" cellpadding="0" cellspacing="0" bgcolor="#95ABCD" id="tb"> <tr> <td width="100%" align="left" valign="top" style="padding:10px;"><font color="<?php print $font_color.'">'.$msg; ?></font></td> </tr></table><?php if ($formdisplay=="show"){ ?><table><tr><td></td></tr></table> <table id="formbg" width="100%" border="0" cellspacing="0" bgcolor="#95ABCD" cellpadding="5"> <tr> <td width="150" align="left" valign="top">Brand Name</td> <td align="left" valign="top"><SELECT NAME="brandname" SIZE="1" tabindex="4" style="width:200px;"><?php $sql = "select * from SL_brands where id='$brandname_final'"; $r1 = mysql_query($sql); if(!empty($sql)){ $browse = mysql_fetch_assoc($r1); $brandnameval=$browse['brand']; }print '<OPTION value="'.$brandname_final.'" SELECTED>'.$brandnameval;?><?php $sql = "select * from SL_brands order by ID asc"; $r1 = mysql_query($sql); if(!empty($sql)){ while ($browse = mysql_fetch_assoc($r1)) { $browse['id']; $brandlist=$browse['brand'];?> <option value="<?php print $browse['id'];?>"><?php print $brandlist;?><?php }}?></SELECT> </td> </tr> <tr> <td width="150" align="left" valign="top">Product</td> <td align="left" valign="top" height="30"><input name="product" tabindex="1" style="width:250px;" type="text" value="<?php echo"$product_final"; ?>"></td> </tr> <tr> <td width="150" align="left" valign="top">Product ID (QuickBooks)</td> <td align="left" valign="top" height="30"><input name="productid" tabindex="1" style="width:250px;" type="text" value="<?php echo"$productid_final"; ?>"></td> </tr> <tr> <td width="150" align="left" valign="top">Retail</td> <td align="left" valign="top" height="30">$ <input name="retail" tabindex="1" style="width:150px;" type="text" value="<?php echo"$retail_final"; ?>"><br><font style="font-size:10px;">Type amount in this format: 29.00.</font></td> </tr> <tr> <td width="150" align="left" valign="top">Order Cost</td> <td align="left" valign="top" height="30">$ <input name="ordercost" tabindex="1" style="width:150px;" type="text" value="<?php echo"$ordercost_final"; ?>"><br><font style="font-size:10px;">Type amount in this format: 29.00.</font></td> </tr><?php$sqltotal=mysql_query("select*from SL_quantity where productid='$pid'");if(!empty($sqltotal)){$totalnum=mysql_num_rows($sqltotal);}if ($totalnum>0) {?> <tr> <td width="150" align="left" valign="top">Sizes </td> <td align="left" valign="top" height="30"><?php $sql = "select * from SL_quantity order by size asc"; $r1 = mysql_query($sql); if(!empty($sql)){ while ($row = mysql_fetch_assoc($r1)) { $current_stock=$row['stock']; $current_size=$row['size']; $mysql_array+=1;?>Size: <input name="<?php print 'mysql_sizes['.$mysql_array.']'; ?>" style="width:60px;" type="text" value="<?php print $current_size; ?>">Stock: <input name="<?php print 'mysql_stock['.$mysql_array.']'; ?>" style="width:60px;" type="text" value="<?php print $current_stock; ?>"><br><font style="font-size:10px;"><p><?php}}}if (isset($size_fields)) {print $size_fields;}$q = implode(",", $sizes);print $q;print $sizes[1];if ($totalnum>0) {?></td></tr><?php}?> <tr> <td width="150" align="left" valign="top"></td><input type="hidden" name="current_array" value="<?php print $current_array; ?>"> <td align="left" valign="top" height="30">Add <input name="add_sizes_amount" tabindex="1" style="width:30px;" type="text" value="1"> more size(s) <input name="add_sizes" type="submit" value="Go"></td> </tr> <tr> <td width="150" align="left" valign="top">Color</td> <td align="left" valign="top" height="30"><input name="color" tabindex="1" style="width:250px;" type="text" value="<?php echo"$color_final"; ?>"></td> </tr> <tr> <td width="150" align="left" valign="top">Description</td> <td align="left" valign="top" height="30"><input name="description" tabindex="1" style="width:250px;" type="text" value="<?php echo"$description_final"; ?>"></td> </tr> <tr> <td width="150" align="left" valign="top">Category</td> <td align="left" valign="top"><SELECT NAME="category" SIZE="1" tabindex="4" style="width:200px;"><?php $sql = "select * from SL_categories where id='$category_final'"; $r1 = mysql_query($sql); if(!empty($sql)){ $browse = mysql_fetch_assoc($r1); $categoryval=$browse['category']; }print '<OPTION value="'.$category_final.'" SELECTED>'.$categoryval;?><?php $sql = "select * from SL_categories order by ID asc"; $r1 = mysql_query($sql); if(!empty($sql)){ while ($browse = mysql_fetch_assoc($r1)) { $browse['id']; $browse['category']; $categorylist=$browse['category'];?> <option value="<?php print $browse['id'];?>"><?php print $categorylist;?><?php }}?></SELECT> </td> </tr></table><table><tr><td></td></tr></table> <table id="formbg" width="100%" border="0" cellspacing="0" bgcolor="#95ABCD" cellpadding="5"> <tr> <td width="150"> </td> <td width="150" align="center"><input name="submit" tabindex="11" type="submit" value="Submit Changes"> </td> <td width="150" align="left" valign="top"> </td> </tr> </table> <?php } ?> </table></form><?phpinclude_once ("../footer.php");?> [/code] Quote Link to comment https://forums.phpfreaks.com/topic/14271-array-and-value/#findComment-56710 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.