-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathajax-dd3ck2.php
executable file
·50 lines (43 loc) · 1.59 KB
/
ajax-dd3ck2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?Php
require "config2.php"; // connection details
error_reporting(0);// With this no error reporting will be there
//////////
/////////////////////////////////////////////////////////////////////////////
$country=$_GET['country'];//
//$country='IND'; // To check you can use this
$state1=$_GET['state'];
$city1=$_GET['city'];
//$state1="Andhra Pradesh";
///////////// Validate the inputs ////////////
// Checking country variable ///
if((strlen($country)) > 0 and (!ctype_alpha($country))){
echo "Data Error";
exit;
}
// Checking state variable (with space ) ///
if ((strlen($state1)) > 0 and ctype_alpha(str_replace(' ', '', $state1)) === false) {
echo "Data Error";
exit;
}
/////////// end of input validation //////
if(strlen($country) > 0){
$q_country="select distinct(state) from student5 where country = '$country' order by state";
}else{
$q_country="select distinct(state) from student5 order by state";
}
//echo $q_country;
$sth = $dbo->prepare($q_country);
$sth->execute();
$state = $sth->fetchAll(PDO::FETCH_COLUMN);
$q_state="select distinct(city) from student5 where ";
if(strlen($country) > 0){
$q_state= $q_state . " country = '$country' ";
}
if(strlen($state1) > 0){$q_state= $q_state . " and state='$state1' order by city";}
$sth = $dbo->prepare($q_state);
$sth->execute();
$city = $sth->fetchAll(PDO::FETCH_COLUMN);
$main = array('state'=>$state,'city'=>$city,'value'=>array("state1"=>"$state1","city1"=>"$city1"));
echo json_encode($main);
////////////End of script /////////////////////////////////////////////////////////////////////////////////
?>