0

I have a simple order form with name (text), date (date), and then 2 sets of dropdowns. Each set contains a dropdown for flange and one for quantity. Basically the set repeats a couple times giving the user the ability to select a flange and then quantity with each set.

The forms sends all of the data (name, date, dropdown values, quantitys etc) to the database. I have created an edit page. When I go to edit an order all the data populates (including the quantity dropdowns) except for the flange dropdowns. They are just default blank.Is there a way to have the flange dropdown populate to the previously selected values?

<div style="display:block;">
          <label for="itemID">1:</label>
          <select id="itemID" name="itemID" required value="<?php echo $row['itemID']; ?>">
                    <option value="1">Flange 1 @ $100</option>
                    <option value="2">Flange 2 @ $100</option>
                    <option value="3">Flange 3 @ $50</option>
                    <option value="4">Flange 4 @ $50</option>
                    <option value="5">Flange 5 @ $50</option>
        </select>
  <label for="quantity"></label>
  <input type="number" id="quantity" name="quantity"  min ='1' max='50' style="width: 3em" required  value="<?php echo $row['quantity']; ?>">
  </div>
  <div style="display:block;">
          <label for="itemID2">1:</label>
          <select id="itemID2" name="itemID2" required value="<?php echo $row['itemID2']; ?>">
                    <option value="1">Flange 1 @ $100</option>
                    <option value="2">Flange 2 @ $100</option>
                    <option value="3">Flange 3 @ $50</option>
                    <option value="4">Flange 4 @ $50</option>
                    <option value="5">Flange 5 @ $50</option>
         </select>
  <label for="quantity2"></label>
  <input type="number" id="quantity2" name="quantity2"  min ='1' max='50' style="width: 3em" required  value="<?php echo $row['quantity2']; ?>">
  </div>
...
2

1 Answer 1

0

You have to set the selected attribute in the option that is currently selected. Like this

<?php
$value1 = $row['itemID'];
?>
  <label for="itemID">1:</label>
  <select id="itemID" name="itemID" required>
    <option value="1" <?php if ($value1=="1") {echo "selected";}?>>Flange 1 @ $100</option>
    <option value="2" <?php if ($value1=="2") {echo "selected";}?>>Flange 2 @ $100</option>
    <option value="3" <?php if ($value1=="3") {echo "selected";}?>>Flange 3 @ $50</option>
    <option value="4" <?php if ($value1=="4") {echo "selected";}?>>Flange 4 @ $50</option>
    <option value="5" <?php if ($value1=="5") {echo "selected";}?>>Flange 5 @ $50</option>
  </select>

And repeat for the 2nd lot.

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you that looks to make sense although I entered the code as is and the page crashes. Am i missing anything else?
Has this got a valid value.$row['itemID']
Yes, all other page functions work. I can place an order from the order page and data gets sent to the database itemID as "1", "2" etc.
Oops, the semicolon was in the wrong place. Fixed above.
The protocol is to tick it as the right answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.