I've been trying to send the value of a select value to a PHP file using Ajax and then use in a SQL query but I can't seem to get it to work.
My select options
<select id="select">
<option value="yes">Yes</option>
<option value="no">No</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
My Ajax request to a PHP file which has the SQL query
$(document).ready(function () {
$('#select').on('change', function () {
var selectValue = $(this).val();
$.ajax({
type: "POST",
url: "phpsqlajax_genxml3_state.php",
data: {
selected: selectValue
},
success: function (data) {
console.log(data);
// Stuff
},
error: function (data) {
// Stuff
}
});
});
});
Then in my PHP file, I have tried this
if(isset($_POST["selected"]))
{
$selectedValue = $_POST['selected'];
$query = "SELECT * FROM customers WHERE delivered='$selectedValue'";
}
And this
$selectedValue = $_POST['selected'];
$query = "SELECT * FROM customers WHERE delivered='$selectedValue'";
The alert pops up the correct value, but it's not updating the variable in the PHP file?