html drill down drop down selected value does not inserted in MYSQL

前端 未结 2 451
臣服心动
臣服心动 2021-01-16 22:19

i have two drop downs. first drop down populate from database. second drop down populated from database based on selected value of first drop down.

相关标签:
2条回答
  • 2021-01-16 23:05

    You need to concantenate them properly and also you don't you put , after last column in the query

    Change following

    $sql1="INSERT INTO table1 (Country, State)
    VALUES ('$c', '$s',)";
    

    to

    $sql1="INSERT INTO table1 (country, state)
    VALUES ('".$c."', '".$s."')";
    
    0 讨论(0)
  • 2021-01-16 23:08

    if want to add options to the second drop down you need to use append not html and your using same ID i.e. #c to write the response in ajax success, change it to second drop down ID i.e. #s

    you can try this:

    $(document).ready(function() {
      $("#c").change(function() {
        var c1 = $('#c :selected').text();
        if(c1 != "") {
          $.ajax({
            url:'getstatw.php',
            data:{c:c1},
            type:'POST',
            success:function(response) {
              var resp = $.trim(response);
              $("#s").append(resp);
            }
          });
        } else {
          $("#c").append("<option selected value=''>Select state</option>");
        }
      });
    });
    

    then remove , in insert query.

    $sql1="INSERT INTO table1 (Country, State)
    VALUES ('$c', '$s')";
    
    0 讨论(0)
提交回复
热议问题