i am building new web application called a store locator for this i need to filter my sql data containing in single table through dependent select boxes and display address of store in table . the problem is that i cant able hold values of two select boxes at same time for sql query
this is my index.php code
<?php
require 'dbconn/dbconfig.php';
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<title>store SEARCH </title>
</head>
<body>
<form name="form1" action="" method="post">
<table>
<tr>
<td>Select store</td>
<td>
<select id="storeid" onchange="change_store()">
<option>Select store</option>
<?php
$res=mysqli_query($db,"SELECT DISTINCT `STORE` FROM `master` ORDER BY `STORE` ASC");
while ($row=mysqli_fetch_array($res)) {
?>
<option value="<?php echo $row['STORE']; ?>"><?php echo $row['STORE'];?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td>Select State</td>
<td>
<div onchange="change_state()">
<select id="statedd" >
<option>select State</option>
</select>
</div>
</td>
</tr>
<tr>
<td>Select District </td>
<td>
<div onchange="change_district()">
<select id="districtdd">
<option>select District</option>
</select>
</div>
</td>
</tr>
<tr>
<td>Select City </td>
<td>
<div onchange="change_city()">
<select id="citydd">
<option>select City</option>
</select>
</div>
</td>
</tr>
<tr>
<td>Select Branch </td>
<td>
<div>
<select id="branchdd">
<option>select Branch</option>
</select>
</div>
</td>
</tr>
</table>
</form>
<script type="text/javascript">
function change_store() {
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","ajax.php?store="+document.getElementById("storeid").value,false);
xmlhttp.send(null);
document.getElementById("statedd").innerHTML=xmlhttp.responseText;
}
function change_state() {
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","ajax.php?state="+document.getElementById("stateid").value,false);
xmlhttp.send(null);
document.getElementById("districtdd").innerHTML=xmlhttp.responseText;
alert(xmlhttp.responseText);
}
function change_district() {
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","ajax.php?district="+document.getElementById("districtid").value,false);
xmlhttp.send(null);
document.getElementById("citydd").innerHTML=xmlhttp.responseText;
}
function change_city() {
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","ajax.php?city="+document.getElementById("cityid").value,false);
xmlhttp.send(null);
document.getElementById("branchdd").innerHTML=xmlhttp.responseText;
}
</script>
</body>
</html>
This is my ajax.php
<?php
include 'dbconn/dbconfig.php';
?>
<?php
$store=$_GET["store"];
$state=$_GET["state"];
if($store!='')
{
$res=mysqli_query($db, "SELECT DISTINCT `STATE` FROM `master` WHERE `STORE`='$store' ORDER BY `STATE` ASC");
echo "<select id='stateid' onchange='change_state()'>";
while ($row=mysqli_fetch_array($res)) {
echo "<option value=".$row['STATE'].">".$row['STATE']."</option>";
}
echo "</select>";
}
if($state!='')
{
$res=mysqli_query($db, "SELECT DISTINCT `DISTRICT` FROM `master` WHERE `STATE` LIKE '$state%' AND `STORE`='$store' ORDER BY `DISTRICT` ASC");
echo "<select id='districtid' onchange='change_district()'>";
while ($row=mysqli_fetch_array($res)) {
echo "<option value=".$row['DISTRICT'].">".$row["DISTRICT"]."</option>";
}
echo "</select>";
}
?>
while changing state it doesn't processing list districts in select boxes console showing an error is
Notice: Undefined index: store in C:\xampp\htdocs\ifsctech\ajax.php on line 5
problem is that the selected value of store is not able to use for next query to process. how to hold and send dynamic values of two select boxes to process query please help