Home » PHP » Ajax country state city dropdown using php & mysql
ajax country state city dropdown using php mysql

Ajax country state city dropdown using php & mysql

Hello friend this post is all about Daynamic Selection of Dropdown in php and Mysql using ajax and jquery. Country city and state dropdown mostly used in new registration of new user and etc.

  • This tutorial will explain you how to make Dependent dropdown of country, state, and city, using ajax. You will find them implemented in various sites registration  form.when the user select country then second dropdown will populate with appropriate  states list then city like wise..
  • This Tutorials load the record dynamically from the database according the user input. with ajax call without refreshing the whole page data will be populate.
  •  country state city Dropdown, using ajax and jqurey fill country state city dropdown.
  • ajax country state city dropdown php, onchange in jquery, dynamic dropdown.

Database & Tables

  • First of all open mysql and create one database dbcountries this database contains three tables country state and city as below. state table has relation with country table and city table has relation with state table.

Country State City tabel

Above are the three table the we use in this tutorials each table have three columns which are dependent to each other.

 Dbconfig.Php

  • Simple Database Configuration file.

 Index.Php

  1. main index file where three dropdown box are available.

 get_state.php

  • This file is for get the all the state record from the state tabel and load dynamically.

 get_city.php

  • In this file have php code for load correlated city according to state selection.
  •  all the main file are displayed remaining css and java script file include normally we do. It’s not big thing.
  • Depending on the dropdown ajax call the function and query should run and get the data from database and populate in dropdown list.
  • Loding image is indicate loding time of ajax function. When Query  response comes then login image invisible.

 Live Demo-:

ajax country state city dropdown using php mysql

 

Live Demo Download

About Bhavin Shiroya

  • Shabrez Khan

    on click of mumbai details of mumbai should be display how to do that

  • 2233

    for example i had selected mumbai and delhi i need to get both states cities in another Dropdown can any one help .

    • yes it is possible but you have to some extra coding to get both the city data.

  • Bilal Yaqoob

    $stmt->execute(array(‘:id’ => $id));
    What is the alternative for that in mysql ?