i have 2 radio buttons male and female when i select male i want the list to be loaded with male names from the database also with female the male and female tables have 2 columns {id} and {name}
<?php 
include "config.php";//database conection
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<script type="text/javascript" src="jquery.min.js"></script>
<div>sexe </div>
<form id="myform">
<input type="radio" id="male" name="gender" value="male" checked="checked">
<label for="male">Male</label><br>
<input type="radio" id="female" name="gender" value="female">
<label for="female">Female</label><br>
</form>
<div>nom</div>
<select id="sel_name">
</select>
<script type="text/javascript">
    $(document).ready(function () {
        $('#myform').change(function () {
            var selected =$("input[name=gender]");           
            $.ajax({
                url:'getnames.php',
                type:'post',
                data:{det:selected},
                dataType:'json',
                success: function (response) {
                   var len = response.length;
                   $('#sel_name').empty();
                   for (var i=0;i<len;i++){
                       var id = response[i]['id'];
                       var name = response[i]['name'];
                       $("#sel_name").append("<option value='"+id+"'>"+name+"</option>");
                   }
                }
            })
        })
    })
</script>
</body>
</html>
and here is the code to get dropdown elements the problem is the dropdown list is still empty i still have a problem with the sql query i get Fatal error: Uncaught Error: Call to a member function execute() on boolean
<?php
include "config.php";
if(isset($_POST["gender"]))
{
$choice = $_POST["gender"];
if ($choice == "male") {
   $table = "male";
}
elseif ($choice =="female") {
   $table = "female";
}
}
$sqli = $conn->prepare("SELECT name FROM ".$table);
$sqli->execute();
$result = $sqli->get_result();
   while ($row = $result->fetch_assoc())
   {
    $id = $row['id'];
    $name = $row['name'];
    
    $persons_array[] =array("id"=>$id,"name"=>$name);
   }
echo json_encode($persons_array);
?>
 
     
    