hello community i need help on this what i really want to do is to select from database using onchange() function through Ajax.then return the result to the client.i used Ajax to send the information to the server side and but i am having problem return it with the where condition
//this is the html page
<body style="font-family:arial bold; ">
<div style="text-align:left; padding:1%; font-family:Arial bold; color:#cccccc;font-size:40px;"> Select</div>
<select class="form-control" id="color" name="color" >
<option >Please select an option</option>
<option> Red</option>
<option >Yellow</option>
<option >white</option>
<option >Black</option>
<option >Violet</option>
</select>
<br/>
//this is where the output will be displayed with parameter (res);
<div id="dis"></div>
</body>
//this is the script.js
$(function(){
$('#color').on('change', function()
{
var selt= this.value ;
d = $('#color').val();
alert(d);
$.ajax({
url: "ajax-cart.php",
method: "POST",
data: {
request:"select",
selt:selt
}
}).done(function(res) {
$('#dis').val(res) ;
console.log(res);
});
});
//this is ajax cart.php
<?php// START THE SESSION
session_start();// CONFIGURATION
require("db.php");
// PROCESS REQUESTS
switch ($_POST['request']) {
// THIS PART is for the select button
case "select":
require("db.php");
$conn = new mysqli($dbServername, $dbUsername, $dbPassword, $dbName );
$val = $_POST['selt'];
$data = $conn->query("SELECT * FROM `goods` where color = '.$val.' LiMIT 4");
echo Json_encode($data);
break;
this is the console result {"current_field":null,"field_count":null,"lengths":null,"num_rows":null,"type":null}