0

The $_POST method is not giving me the value of the selected option in my select box:

<div class="amazonpackaging_form">
<div class="inner_form">
         <p>Select an Option to choose a SKU:</p>
        <form class="rad_buttons_1" action="" method="POST">
            <input type="radio" name="jewelry_type" value="locket"><label name="type" value="locket">Lockets</label><br>
            <input type="radio" name="jewelry_type" value="jewelry"><lable name="type" value="jewelry">Jewelry</label><br>
            <input type="submit" name="submit" value="submit">
        </form>
        <?
            global $radio_input;
            if (isset($_POST['submit']) and ! empty($_POST['submit'])){
                if (isset($_POST['jewelry_type'])){
                    $radio_input = $_POST['jewelry_type'];
                }
            }
        ?>
</div>

<div class="inner_form">
    <form action="" method="POST">
        <?  
            $flag = "false";
            global $JEWELRY_SKU;
            if (isset($_POST['submit']) and ! empty($_POST['submit'])){
                echo "<p class='title'>SKU:</p>";
                if ($radio_input == "locket"){
                    $sql_1 = "SELECT SKU FROM tblLocketInventory";
                    $flag = "true";
                }
                elseif ($radio_input == "jewelry"){
                    $sql_1 = "SELECT SKU FROM tblJewelryInventory";
                    $flag = "true";
                }
                if ($flag == "true"){
                    $result_1 = $conn->query($sql_1);
                    $counter = 1;
                    $db_sku_list = array();
                    if ($result_1->num_rows > 0) {
                        while($row = $result_1->fetch_assoc()) {
                            $db_sku_list[$counter] = $row["SKU"];
                            $counter = $counter + 1;
                        }
                    }
                    $counter = 1;
                    echo "<select name='sku_select'>";
                    foreach ($db_sku_list as $_sku){
                        if ($counter == 1){
                            echo "<option value=".$_sku." selected='selected'  name = ".$_sku.">".$_sku."</option>";
                        }
                         else {
                            echo "<option value = ".$_sku." name = ".$_sku.">".$_sku."</option>";
                        }
                        $counter++;
                     }
                     echo "</select>";
                 }
                 $JEWELRY_SKU = $_POST['sku_select'];
                 echo "<div class='split1'><p>Quantity Used:</p><input type='text' name='quantity' class='form_inputbox1'></div>";
                 echo "<div class='split2'><p>Quantity Damaged:</p><input type='text' name='quantity' class='form_inputbox1'></div>";
            }
        ?>
    </form>
</div>
</div>
<?
     $JEWELRY_SKU = $_POST['sku_select'];
     if ($radio_input == "locket"){
         include ("amazonlockets.inc");
     }
?>

I'm getting an error on the line

$JEWELRY_SKU = $_POST['sku_select'];

Notice: Undefined index: sku_select in /Applications/XAMPP/xamppfiles/htdocs/ATDWebApp/sku.inc on line 65

I've tried playing around with this in numerous ways, but I cannot figure out why I'm not getting a value from this.

I have tried putting it in a separate form in separate php code and I still have the same error. Any ideas why?

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
Adina
  • 113
  • 1
  • 12
  • You are definitely going to get that error once you first open the page. $_POST values only exist when a page has been "posted" to, meaning once you actually submit the form. So when you try to reference `$_POST['sku_select']` at the bottom, there is nothing there before you submit the form. – aaronofleonard May 23 '16 at 16:46
  • This line `$JEWELRY_SKU = $_POST['sku_select'];` is inside AND outside your "if"... Check again. – Felippe Duarte May 23 '16 at 16:46
  • @felippeduarte i have tried with it inside and outside neither are working – Adina May 23 '16 at 17:02
  • if (isset($_POST['sku_select'])){ $JEWELRY_SKU = $_POST['sku_select']; } else { $JEWELRY_SKU = ''; } – Duane Lortie May 23 '16 at 17:15
  • thanks @FelippeDuarte that was the issue- it works now! – Adina May 25 '16 at 15:09

0 Answers0