jQuery Dependent Drop Down List–Country, States and City in PHP

In this tutorial, we discuss how to change the country state city dropdown list in PHP using jQuery ajax from the MySQL database.

In this example, we will guide you step by step on to change country state city in the dropdown list on change in PHP from  MySQL using jQuery.

 

Drop down list using PHP and MySQL by JQuery will look Like as follow.

jQuery Dependent DropDown List – Country, States and City

First, create HTML Form with three select fields.

Getting States using jQuery AJAX

This script contains a function that will be called on changing country dropdown values. It will send AJAX request to a PHP page to get corresponding State dropdown options.

Read State Database using PHP

This PHP code connects the database to retrieve state table values based on the country id passed by jQuery AJAX call.

Getting States using jQuery AJAX

This script contains a function that will be called on changing states dropdown values. It will send AJAX request to a PHP page to get corresponding city dropdown options.

Read City Database using PHP

This PHP code connects the database to retrieve city table values based on the state id passed by the jQuery AJAX call.

How to Run the Script

Download the script zip after that extract the zip file

Copy countrystatecitydropdown folder and paste in the root directory

Now create the database with the name demosdb after that import the SQL file available in the script folder

Now Run the script http://localhos/countrystatecitydropdown/

Click : https://phpgurukul.com/jquery-dependent-drop-down-list-country-states-and-city-in-php/

Showing 1 reaction

Please check your e-mail for a link to activate your account.
  • glasgow insights
    published this page in Submit Content 2022-07-10 10:36:17 -0700

connect