In my web page I have two select options in a single form. first select option is categories which is fetched from MySQL table using PHP and works fine. But second select option shows sub-categories which needs to be fetched from MySQL table based on user selected categories option. I dont know ajax, jQuery codes to use with MySQL database. Here is my code
first select option(works fine)
<select class="form-control" name="catid" required>
<option value="">select</option>
<?php
$sql="select cat_id,cat_name from tbl_categories";
$query=mysqli_query($conn,$sql);
while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){ ?>
<option value="<?php echo $row['cat_id'];?>"><?php echo ($row['cat_name']); ?></option>
<?php
}
if(isset($_POST['catid'])){
$cid=$_POST['catid'];
}
?>
</select>
second select option(not working)
<select class="form-control" name="subcatid" required>
<option value="">select</option>
<?php
$sql2="select s_id,subcat_name from tbl_subcategories where cat_id='$cid' order by subcat_name";
$query2=mysqli_query($conn,$sq2);
while($row2 = mysqli_fetch_array($query2, MYSQLI_ASSOC)){ ?>
<option value="<?php echo $row2['s_id'];?>"><?php echo ($row2['subcat_name']); ?></option>
<?php } ?>
</select>