通过使用php和javascript选择一个选项来更新数据库表

I'm trying to update a table column in my database, by selecting an option from a selectbox using php and jquery. Such that when a user clicks on an option, the site returns a text value to the category column in the database. I've really tried understanding the concept to apply, any help will be appreciated.

my database table, selecting an option updates the category column my code attempt

enter code here
<div class="upload_wrapper">
        <select id="selectbox" name="options">
            <option value="" selected>Select Category</option>
            <option value="Furniture">Furniture</option>
            <option value="Tableware">Tableware</option>
            <option value="Jewellery">Jewellery</option>
            <option value="Shoes">Shoes</option>
            <option value="Water Bottles">Water Bottles</option>
            <option value="Clothes">Clothes</option>
            <option value="Fabric Patterns">Fabric Patterns</option>
        </select>
    <?php 
    include('connect.php');


    if(isset($_POST['options'])){
        $sql = "INSERT INTO images (category) VALUES ($_POST["options"])";
    }
    $select_category = array('Furniture', 'Tableware', 'Jewellery', 'Shoes', 'Water Bottles', 'Clothes', 'Fabric Patterns');


    ?>
    <script>
    $('#selectbox').change(function(){

        $sql = $($('#selectbox option:selected').text();

        });
    </script>

    </div>

You should be able to do this.

Example from my own project, where I'm fetching some categories from a database table:

$result = mysqli_query($con,$sql)or die(mysqli_error());
      if (mysqli_num_rows($result) > 0) {
         //open the select tag before the loop
         echo"<select name='category'>";
         //populate the select
         while($row = mysqli_fetch_assoc($result)) {

            $name=$row["Name"];

            echo"<option value=" .$name.">".$name."</option>"  ;
         }
         //close the select tag after the loop
         echo"</select>";
         echo "<br>";
      } else {
         echo "0 results";
      } ?>

I can then show the clicked option value using this variable in my sql query:

 $category = mysqli_real_escape_string($link, $_REQUEST['category']);

$link is my sql connection.

you must be using ajax, if you want to insert data to table on every selection of your dropdown.

first add this script to your html.

<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script> 

Change your script to this:

$(document).ready(function() {

$('#selectbox').change(function(){

    $sql = $(this).val();


        $.ajax({
        url:"filename of your php file",
        method:"POST",
        data:{
            CatNAME:$sql
            },
        dataType:"json",
       success:function(data){


             alert("INSERTED SUCCESSFULLY");

            }
        })

    });
  });

And your condition on php to this:

 if(isset($_POST['CatNAME'])){
    $catname = $_POST["CatNAME"];
    $sql = "INSERT INTO images (category) VALUES ('$catname')";
}

NOTE: Dont forget the url: on ajax which is the php file itself.