How to pull the Option value from the select HTML property that is saved in MYSQL

Asked

Viewed 21 times

0

How do I change and be saved in the database, once I update the saved value is filled in the box, the way I am doing saved in the bank, but when updating the page it always leaves the box filled with the first value.

   $ifs = "SELECT * FROM config WHERE id='1'";
   $sqs = mysqli_query($conn, $ifs);
   $sda = mysqli_fetch_assoc($sqs);

   if (isset($_POST['aspect'])){


    $atext = mysqli_real_escape_string($conn,$_POST['aspect']);

    $sql = "UPDATE `config` SET `aspect` = '$atext' WHERE `id` = 1";
    $ssl = mysqli_query($conn, $sql);

    header("Location: settings-jw.php");
    exit();

   }

<form  action="" method="post" >
   <div class="col-sm-12 col-lg-4">
      <div class="form-group">
         <label for="aspect">Aspect Ratio:</label> <i class="fa fa-info-circle" data-toggle="tooltip" title="Aspect ratio"></i>
         <select id="aspect" name="aspect" class="form-control">
            <option value="16:9">16:9</option>
            <option value="4:3">4:3</option>
         </select>
      </div>
   </div>
   <input type="submit" class="btn btn-danger" value="Salvar" />
</form>

1 answer

0


You would need to add some conditions in your select for this. Example:

<option <?php if($sda['aspect'] == '16:9') echo 'selected' ?> value="16:9">16:9</option>
  • thank you very much, it has helped a lot! , it may seem a little silly things, but I do not possess much knowledge, so I need help rs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.