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.
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."')";
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')";