I have a web page with a large number of select boxes plus a few other types of inputs. I want to populate these select boxes and input boxes with values held in a MySQL database based on the values selected in two of the select boxes. I have tried to use AJAX to request the data but cannot see how to return the data held in a database to a specific select box from the server php script. jscript used to request the data is as follows
<script>
function venueChange(str) {
if (str == "") {
document.getElementById("Venue").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("Player1").innerHTML = this.responseText;
}
};
var opponent_name = document.getElementById("Opponents").value
var variables = "venue_name=str&opponent_name=Hello World";
xmlhttp.open("GET","getTeamPHP?" + variables,true);
xmlhttp.send();
}
}
</script>
The getTeamPHP files is as follows;
<?php
require '../../configure.php';
$q = intval($_GET['venue_name']);
$v = $_GET['opponent_name'];
$database = "matchmanagementdb";
$con = mysqli_connect(DB_SERVER, DB_USER, DB_PASS,$database);
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
//mysqli_select_db($con,$database);
$sql="SELECT * FROM user WHERE Opponents = '".$q."' AND Venue = '".$v."'";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result)) {
echo document.getElementById("Player1").innerHTML = $row['FirstName'] ;
}
mysqli_close($con);
?>