Reputation: 51
Last time i post my uncomplete question from my phone. Now here is my complete question. Okay So my problem is that i build an edit page editProduct.php. Here i build three forms as i have Three Categories Each Category have its own form. These three forms have almost everything is same.e.g: Product Name input box, condition Select box and more. i view product page when i click edit button edit page open and in a field it show the current value of product in input box and also in select box also in checkbox.Here is my HTML Code.
<input type="text" name="p_name[]" value="<?php echo $db_pname; ?>" placeholder="Product Name">
<select name="guarented-delivery[]" id="guarented-delivery">
<option value="1 Days Shipping" <?php if($db_gdelivery=="1 Days Shipping") { echo 'selected="selected"'; } ?>>1 days</option>
<option value="2 Days shipping" <?php if($db_gdelivery=="2 Days shipping") { echo 'selected="selected"'; } ?>>2 days</option>
<option value="3 Days shipping" <?php if($db_gdelivery=="3 Days shipping") { echo 'selected="selected"'; } ?>>3 days</option>
<option value="5 Days shipping" <?php if($db_gdelivery=="5 Days shipping") { echo 'selected="selected"'; } ?>>5 days</option>
<option value="7 Days shipping" <?php if($db_gdelivery=="7 Days shipping") { echo 'selected="selected"'; } ?>>7 days</option>
<option value="10 Days shipping" <?php if($db_gdelivery=="10 Days shipping") { echo 'selected="selected"'; } ?>>10 days</option>
</select>
Okay so this is the example, and i have three categories and each category form i use same code like this. i use [] with name attribute as it used in all forms so that it get value of all in array. but don't know how to get the value of of selected or new text in input box? as it shows me the old value not new entered value. Here is my php code.
$name = $_POST['p_name'];
foreach($name as $pname)
{
$pname;
// if i echo here then i shows me old product name 3 times echo outside this loop to get value 1 time.
}
echo $pname;
//for dropdown
$gd = $_POST['gdelivery'];
foreach($gd as $gdelivery)
{
$gdelivery;
}
echo $gdelivery;
help me solve this problem. Thanks.
Upvotes: 0
Views: 395
Reputation: 9145
After discussing your comments, this will work for you:
Important is, that all selects must be within the same form.
<form method="post">
<select name="colors[]"><option value="black">black</option></select>
<select name="colors[]"><option value="red">red</option></select>
<select name="colors[]"><option value="gold">gold</option></select>
<input type="submit">
</form>
<?php
$colors = isset($_POST['colors']) ? (array) $_POST['colors'] : [];
foreach($colors as $color)
{
echo "$color<br>\n";
}
// black
// red
// gold
Upvotes: 2