{"id":1489,"date":"2017-05-08T16:58:46","date_gmt":"2017-05-08T11:28:46","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=1489"},"modified":"2026-08-21T15:58:16","modified_gmt":"2026-08-21T10:28:16","slug":"dynamic-dependent-drop-list-using-htmlphpmysqlajax","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/dynamic-dependent-drop-list-using-htmlphpmysqlajax\/","title":{"rendered":"Dynamic dependent drop-down list using HTML, PHP, MySQL, and AJAX"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>A dependent dropdown list is a common feature used in web applications where the options in one dropdown depend on the value selected in another dropdown.<\/p>\n<p>For example, when a user selects a country from the first dropdown, the second dropdown can automatically display the states or regions belonging to that country. This improves the user experience by displaying only relevant options.<\/p>\n<p>In this guide, we will learn how to create a dynamic dependent dropdown list using <strong>HTML, PHP, MySQL, JavaScript, and AJAX<\/strong>. The example uses two dropdown lists: one for countries and another for states.<\/p>\n<p><strong>Note:<\/strong> The original implementation of this article uses PHP&#8217;s old <code>mysql_*<\/code> functions. These functions were deprecated in PHP 5.5 and removed in PHP 7. The implementation below uses <strong>MySQLi<\/strong>, which is suitable for modern PHP environments.<\/p>\n<hr \/>\n<h2>Prerequisites<\/h2>\n<p>Before implementing the dynamic dependent dropdown, make sure you have:<\/p>\n<ul>\n<li>\n<p>Basic knowledge of HTML.<\/p>\n<\/li>\n<li>\n<p>Basic knowledge of PHP.<\/p>\n<\/li>\n<li>\n<p>Basic knowledge of MySQL.<\/p>\n<\/li>\n<li>\n<p>Basic understanding of JavaScript and AJAX.<\/p>\n<\/li>\n<li>\n<p>A web server such as Apache or Nginx.<\/p>\n<\/li>\n<li>\n<p>PHP installed on the server.<\/p>\n<\/li>\n<li>\n<p>MySQL or MariaDB installed and running.<\/p>\n<\/li>\n<li>\n<p>A database and user with permission to create and read tables.<\/p>\n<\/li>\n<li>\n<p>jQuery, if you want to use the AJAX approach shown in this guide.<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h2>Implementation<\/h2>\n<h3>1. Create the Database<\/h3>\n<p>First, create a database for the application.<\/p>\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">CREATE DATABASE demo;<\/pre>\n\n\n\n<p>Select the database:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">USE demo;<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">USE demo;<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">2. Create the Countries Table<\/h3>\n\n\n\n<p>Create a table to store country information:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">CREATE TABLE ls_countries (\n     country_id INT NOT NULL AUTO_INCREMENT, \n     sortname VARCHAR(3) NOT NULL, \n     name VARCHAR(150) NOT NULL, \n     phonecode INT NOT NULL, \n     status INT NOT NULL, P\n     RIMARY KEY (country_id) \n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;<\/pre>\n\n\n\n<p>The <code>country_id<\/code> column uniquely identifies each country.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">3. Create the States Table<\/h3>\n\n\n\n<p>Next, create a table to store states or regions:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">CREATE TABLE ls_states ( \n    state_id INT NOT NULL, \n    name VARCHAR(100) NOT NULL, \n    country_id INT NOT NULL, \n    status INT NOT NULL, \n    PRIMARY KEY (state_id), \n    FOREIGN KEY (country_id) REFERENCES ls_countries(country_id) \n);<\/pre>\n\n\n\n<p>The <code>country_id<\/code> column connects each state with its corresponding country.<\/p>\n\n\n\n<p>This relationship allows us to retrieve states based on the country selected by the user.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">4. Create the Database Connection<\/h3>\n\n\n\n<p>Create a file named <code>db.php<\/code> to handle the database connection.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php \n\n$host = \"localhost\"; \n$user = \"root\"; \n$password = \"\"; \n$database = \"demo\"; \n\n$conn = new mysqli($host, $user, $password, $database); \nif ($conn->connect_error) {\ndie(\"Database connection failed: \" . $conn->connect_error); \n}<\/pre>\n\n\n\n<p>Using a separate connection file makes the application easier to maintain because the same database connection can be reused by multiple PHP files.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">5. Create the Country Dropdown<\/h3>\n\n\n\n<p>Create a file named <code>dropdown-ajax.php<\/code>.<\/p>\n\n\n\n<p>Start by including the database connection:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php \nrequire_once \"db.php\"; \n?><\/pre>\n\n\n\n<p>Retrieve the available countries:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php \n\n$sql = \"SELECT country_id, name \n        FROM ls_countries \n        WHERE status = 1 \n        ORDER BY name\"; \n\n$result = $conn->query($sql); \n\n?><\/pre>\n\n\n\n<p>Create the dropdown:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;select id=\"country\" onchange=\"fetch_select(this.value)\">\n    &lt;option value=\"\">Select country&lt;\/option> \n    &lt;?php while ($row = $result->fetch_assoc()): ?> \n        &lt;option value=\"&lt;?= htmlspecialchars($row['country_id']) ?>\"> \n           &lt;?= htmlspecialchars($row['name']) ?>\n        &lt;\/option> \n    &lt;?php endwhile; ?> \n&lt;\/select> \n\n&lt;select id=\"new_select\"> \n    &lt;option value=\"\">Select state&lt;\/option> \n&lt;\/select><\/pre>\n\n\n\n<p>The first dropdown displays the available countries.<\/p>\n\n\n\n<p>When the user selects a country, the <code>fetch_select()<\/code> JavaScript function is called.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">6. Add AJAX Functionality<\/h3>\n\n\n\n<p>Include jQuery in the HTML page:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function fetch_select(countryId) { \n\n   if (!countryId) {\n        document.getElementById(\"new_select\").innerHTML = \n           '&lt;option value=\"\">Select state&lt;\/option>'; \n        return; \n   } \n   $.ajax({ \n      type: \"POST\", \n      url: \"fetch_data.php\", \n      data: { \n        get_option: countryId\n      }, \n     success: function(response) { \n        document.getElementById(\"new_select\").innerHTML = response; \n      }, \n     error: function() { \n       document.getElementById(\"new_select\").innerHTML =\n         '&lt;option value=\"\">Unable to load states&lt;\/option>'; \n     } \n   }); \n}<\/pre>\n\n\n\n<p>The AJAX request sends the selected <code>country_id<\/code> to <code>fetch_data.php<\/code>.<\/p>\n\n\n\n<p>The response from <code>fetch_data.php<\/code> is then inserted into the second dropdown.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">7. Create the AJAX PHP File<\/h3>\n\n\n\n<p>Create another file named <code>fetch_data.php<\/code>.<\/p>\n\n\n\n<p>Include the database connection:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">7. Create the AJAX PHP File<\/h3>\n\n\n\n<p>Create another file named <code>fetch_data.php<\/code>.<\/p>\n\n\n\n<p>Include the database connection:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nrequire_once \"db.php\";<\/pre>\n\n\n\n<p>Check whether a country ID was received:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">if (isset($_POST['get_option'])) {\n\n    $countryId = filter_input(\n        INPUT_POST,\n        'get_option',\n        FILTER_VALIDATE_INT\n    );\n\n    if (!$countryId) {\n        exit;\n    }\n\n    \/\/ Continue with the database query...\n}<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">8. Retrieve States for the Selected Country<\/h3>\n\n\n\n<p>Use a prepared statement to safely retrieve the states:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$stmt = $conn->prepare(\n    \"SELECT state_id, name\n     FROM ls_states\n     WHERE country_id = ? AND status = 1\n     ORDER BY name\"\n);\n\n$stmt->bind_param(\"i\", $countryId);\n$stmt->execute();\n\n$result = $stmt->get_result();<\/pre>\n\n\n\n<p>Prepared statements help prevent SQL injection and are preferable to directly inserting user input into SQL queries.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">9. Return the States as Dropdown Options<\/h3>\n\n\n\n<p>Loop through the results and generate the <code>&lt;option&gt;<\/code> elements:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">echo '&lt;option value=\"\">Select state&lt;\/option>';\n\nwhile ($row = $result->fetch_assoc()) {\n    echo '&lt;option value=\"' .\n         htmlspecialchars($row['state_id']) .\n         '\">' .\n         htmlspecialchars($row['name']) .\n         '&lt;\/option>';\n}<\/pre>\n\n\n\n<p>The complete <code>fetch_data.php<\/code> can be written as:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nrequire_once \"db.php\";\n\nif (!isset($_POST['get_option'])) {\n    exit;\n}\n\n$countryId = filter_input(\n    INPUT_POST,\n    'get_option',\n    FILTER_VALIDATE_INT\n);\n\nif (!$countryId) {\n    exit;\n}\n\n$stmt = $conn->prepare(\n    \"SELECT state_id, name\n     FROM ls_states\n     WHERE country_id = ? AND status = 1\n     ORDER BY name\"\n);\n\n$stmt->bind_param(\"i\", $countryId);\n$stmt->execute();\n\n$result = $stmt->get_result();\n\necho '&lt;option value=\"\">Select state&lt;\/option>';\n\nwhile ($row = $result->fetch_assoc()) {\n    echo '&lt;option value=\"' .\n         htmlspecialchars($row['state_id']) .\n         '\">' .\n         htmlspecialchars($row['name']) .\n         '&lt;\/option>';\n}\n\n$stmt->close();\n$conn->close();<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Complete Example<\/h2>\n\n\n\n<p>The complete <code>dropdown-ajax.php<\/code> file can be structured as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nrequire_once \"db.php\";\n\n$sql = \"SELECT country_id, name\n        FROM ls_countries\n        WHERE status = 1\n        ORDER BY name\";\n\n$result = $conn->query($sql);\n\n?>\n\n&lt;!DOCTYPE html>\n&lt;html lang=\"en\">\n&lt;head>\n    &lt;meta charset=\"UTF-8\">\n    &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n\n    &lt;title>Dependent Dropdown&lt;\/title>\n\n    &lt;script src=\"https:\/\/code.jquery.com\/jquery-3.7.1.min.js\">&lt;\/script>\n\n    &lt;script>\n        function fetch_select(countryId) {\n\n            if (!countryId) {\n                document.getElementById(\"new_select\").innerHTML =\n                    '&lt;option value=\"\">Select state&lt;\/option>';\n                return;\n            }\n\n            $.ajax({\n                type: \"POST\",\n                url: \"fetch_data.php\",\n                data: {\n                    get_option: countryId\n                },\n                success: function(response) {\n                    document.getElementById(\"new_select\").innerHTML =\n                        response;\n                },\n                error: function() {\n                    document.getElementById(\"new_select\").innerHTML =\n                        '&lt;option value=\"\">Unable to load states&lt;\/option>';\n                }\n            });\n        }\n    &lt;\/script>\n&lt;\/head>\n\n&lt;body>\n\n    &lt;label for=\"country\">Country:&lt;\/label>\n\n    &lt;select id=\"country\" onchange=\"fetch_select(this.value)\">\n        &lt;option value=\"\">Select country&lt;\/option>\n\n        &lt;?php while ($row = $result->fetch_assoc()): ?>\n            &lt;option value=\"&lt;?= htmlspecialchars($row['country_id']) ?>\">\n                &lt;?= htmlspecialchars($row['name']) ?>\n            &lt;\/option>\n        &lt;?php endwhile; ?>\n    &lt;\/select>\n\n    &lt;label for=\"new_select\">State:&lt;\/label>\n\n    &lt;select id=\"new_select\">\n        &lt;option value=\"\">Select state&lt;\/option>\n    &lt;\/select>\n\n&lt;\/body>\n&lt;\/html><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">How the Dynamic Dropdown Works<\/h2>\n\n\n\n<p>The complete process works as follows:<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>The PHP application retrieves the list of countries from MySQL.<\/li>\n\n\n\n<li>The countries are displayed in the first dropdown.<\/li>\n\n\n\n<li>The user selects a country.<\/li>\n\n\n\n<li>The <code>onchange<\/code> event calls the JavaScript <code>fetch_select()<\/code> function.<\/li>\n\n\n\n<li>AJAX sends the selected <code>country_id<\/code> to <code>fetch_data.php<\/code>.<\/li>\n\n\n\n<li>PHP receives the country ID.<\/li>\n\n\n\n<li>PHP queries the <code>ls_states<\/code> table for matching states.<\/li>\n\n\n\n<li>The matching states are returned as HTML <code>&lt;option&gt;<\/code> elements.<\/li>\n\n\n\n<li>JavaScript inserts the response into the second dropdown.<\/li>\n\n\n\n<li>The user can select a state associated with the selected country.<\/li>\n<\/ol>\n\n\n\n<p>This process happens without reloading the entire web page.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Security Considerations<\/h2>\n\n\n\n<p>When implementing dependent dropdowns in a production application, consider the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Avoid the deprecated <code>mysql_*<\/code> PHP functions.<\/li>\n\n\n\n<li>Use MySQLi or PDO for database connections.<\/li>\n\n\n\n<li>Use prepared statements for queries involving user input.<\/li>\n\n\n\n<li>Validate and sanitize incoming values.<\/li>\n\n\n\n<li>Escape database output before displaying it in HTML.<\/li>\n\n\n\n<li>Do not expose database credentials in publicly accessible files.<\/li>\n\n\n\n<li>Use HTTPS when transmitting application data.<\/li>\n\n\n\n<li>Restrict database users to the permissions they actually need.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>A dynamic dependent dropdown is useful when the options in one field depend on the selection made in another field. Using HTML, PHP, MySQL, JavaScript, and AJAX, developers can dynamically retrieve and display related data without reloading the entire page.<\/p>\n\n\n\n<p>In this example, countries are displayed in the first dropdown, and the states associated with the selected country are dynamically retrieved from MySQL and displayed in the second dropdown.<\/p>\n\n\n\n<p>For modern PHP applications, it is important to replace the deprecated <code>mysql_*<\/code> functions used in older implementations with <strong>MySQLi or PDO<\/strong>, along with prepared statements and appropriate input validation.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">FAQs<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. What is a dependent dropdown list?<\/h3>\n\n\n\n<p>A dependent dropdown list is a dropdown whose available options depend on the value selected in another dropdown.<\/p>\n\n\n\n<p>For example, selecting <strong>India<\/strong> in the country dropdown can display only Indian states in the state dropdown.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Why is AJAX used for dependent dropdowns?<\/h3>\n\n\n\n<p>AJAX allows the application to retrieve the required data from the server without refreshing the entire webpage.<\/p>\n\n\n\n<p>When a user selects a country, only the state information needs to be requested and updated.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Can this implementation be used without jQuery?<\/h3>\n\n\n\n<p>Yes. The same functionality can be implemented using JavaScript&#8217;s native <code>fetch()<\/code> API or <code>XMLHttpRequest<\/code>. jQuery is used in this example because the original implementation uses jQuery AJAX.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Related Articles<\/h2>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>Send Email Using HTML Templates in CodeIgniter<\/strong> \u2013 Learn how to send emails using HTML templates with CodeIgniter.<br><a href=\"https:\/\/pheonixsolutions.com\/blog\/send-email-using-html-templates-codeigniter\/?utm_source=chatgpt.com\">Send Email Using HTML Templates in CodeIgniter<\/a><\/li>\n\n\n\n<li><strong>How to Install Nginx and Let&#8217;s Encrypt SSL with HTML, Docker and Ubuntu 20.04<\/strong> \u2013 Learn how to configure Nginx, Docker, and Let&#8217;s Encrypt SSL on Ubuntu.<br><a href=\"https:\/\/pheonixsolutions.com\/blog\/how-to-install-nginx-and-lets-encrypt-ssl-with-html-docker-ubuntu-20-04\/?utm_source=chatgpt.com\">How to Install Nginx and Let&#8217;s Encrypt SSL with HTML, Docker and Ubuntu 20.04<\/a><\/li>\n\n\n\n<li><strong>Install PHP 7.2 Mcrypt Module on Ubuntu 18.04<\/strong> \u2013 Learn how to install and configure the PHP Mcrypt module on Ubuntu.<br><a href=\"https:\/\/pheonixsolutions.com\/blog\/install-php-7-2-mcrypt-module-on-ubuntu-18-04\/?utm_source=chatgpt.com\">Install PHP 7.2 Mcrypt Module on Ubuntu 18.04<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Introduction A dependent dropdown list is a common feature used in web applications where the options in one dropdown depend on the value selected in another dropdown. For example, when a user selects a country from the first dropdown, the second dropdown can automatically display the states or regions belonging&hellip; <a href=\"https:\/\/pheonixsolutions.com\/blog\/dynamic-dependent-drop-list-using-htmlphpmysqlajax\/\" class=\"more-link read-more\" rel=\"bookmark\">Continue Reading <span class=\"screen-reader-text\">Dynamic dependent drop-down list using HTML, PHP, MySQL, and AJAX<\/span><i class=\"fa fa-arrow-right\"><\/i><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[221],"tags":[341,179,273],"class_list":{"0":"post-1489","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-php","7":"tag-codeigniter","8":"tag-mysql-2","9":"tag-php","10":"h-entry","12":"h-as-article"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Dynamic Dependent Dropdown Using PHP, MySQL &amp; AJAX<\/title>\n<meta name=\"description\" content=\"Learn how to create a dynamic dependent dropdown using PHP, MySQL, HTML, JavaScript and AJAX to load related options without refreshing the page.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/pheonixsolutions.com\/blog\/dynamic-dependent-drop-list-using-htmlphpmysqlajax\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Dynamic Dependent Dropdown Using PHP, MySQL &amp; AJAX\" \/>\n<meta property=\"og:description\" content=\"Learn how to create a dynamic dependent dropdown using PHP, MySQL, HTML, JavaScript and AJAX to load related options without refreshing the page.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/pheonixsolutions.com\/blog\/dynamic-dependent-drop-list-using-htmlphpmysqlajax\/\" \/>\n<meta property=\"og:site_name\" content=\"PHEONIXSOLUTIONS\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/PheonixSolutions-209942982759387\/\" \/>\n<meta property=\"article:published_time\" content=\"2017-05-08T11:28:46+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-08-21T10:28:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2016\/09\/PX2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"3837\" \/>\n\t<meta property=\"og:image:height\" content=\"2540\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@pheonixsolution\" \/>\n<meta name=\"twitter:site\" content=\"@pheonixsolution\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/dynamic-dependent-drop-list-using-htmlphpmysqlajax\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/dynamic-dependent-drop-list-using-htmlphpmysqlajax\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/0ffa33d73c869faec2d50e79c24e3503\"},\"headline\":\"Dynamic dependent drop-down list using HTML, PHP, MySQL, and AJAX\",\"datePublished\":\"2017-05-08T11:28:46+00:00\",\"dateModified\":\"2026-08-21T10:28:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/dynamic-dependent-drop-list-using-htmlphpmysqlajax\\\/\"},\"wordCount\":944,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/#organization\"},\"keywords\":[\"codeigniter\",\"mysql\",\"php\"],\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/dynamic-dependent-drop-list-using-htmlphpmysqlajax\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/dynamic-dependent-drop-list-using-htmlphpmysqlajax\\\/\",\"url\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/dynamic-dependent-drop-list-using-htmlphpmysqlajax\\\/\",\"name\":\"Dynamic Dependent Dropdown Using PHP, MySQL & AJAX\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/#website\"},\"datePublished\":\"2017-05-08T11:28:46+00:00\",\"dateModified\":\"2026-08-21T10:28:16+00:00\",\"description\":\"Learn how to create a dynamic dependent dropdown using PHP, MySQL, HTML, JavaScript and AJAX to load related options without refreshing the page.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/dynamic-dependent-drop-list-using-htmlphpmysqlajax\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/dynamic-dependent-drop-list-using-htmlphpmysqlajax\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/dynamic-dependent-drop-list-using-htmlphpmysqlajax\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Dynamic dependent drop-down list using HTML, PHP, MySQL, and AJAX\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/\",\"name\":\"Pheonix Solutions\",\"description\":\"We Empower Your Business Growth\",\"publisher\":{\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/#organization\",\"name\":\"PheonixSolutions\",\"url\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/12\\\/logo.png\",\"contentUrl\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/12\\\/logo.png\",\"width\":454,\"height\":300,\"caption\":\"PheonixSolutions\"},\"image\":{\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/PheonixSolutions-209942982759387\\\/\",\"https:\\\/\\\/x.com\\\/pheonixsolution\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/0ffa33d73c869faec2d50e79c24e3503\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/09bacc0294abee1322a23ab4bc6a0330dd4cb4df707dc9d0b0efeba6c109608b?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/09bacc0294abee1322a23ab4bc6a0330dd4cb4df707dc9d0b0efeba6c109608b?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/09bacc0294abee1322a23ab4bc6a0330dd4cb4df707dc9d0b0efeba6c109608b?s=96&r=g\",\"caption\":\"admin\"},\"sameAs\":[\"http:\\\/\\\/pheonixsolutions.com\\\/blog\"],\"url\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/author\\\/admin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Dynamic Dependent Dropdown Using PHP, MySQL & AJAX","description":"Learn how to create a dynamic dependent dropdown using PHP, MySQL, HTML, JavaScript and AJAX to load related options without refreshing the page.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/pheonixsolutions.com\/blog\/dynamic-dependent-drop-list-using-htmlphpmysqlajax\/","og_locale":"en_US","og_type":"article","og_title":"Dynamic Dependent Dropdown Using PHP, MySQL & AJAX","og_description":"Learn how to create a dynamic dependent dropdown using PHP, MySQL, HTML, JavaScript and AJAX to load related options without refreshing the page.","og_url":"https:\/\/pheonixsolutions.com\/blog\/dynamic-dependent-drop-list-using-htmlphpmysqlajax\/","og_site_name":"PHEONIXSOLUTIONS","article_publisher":"https:\/\/www.facebook.com\/PheonixSolutions-209942982759387\/","article_published_time":"2017-05-08T11:28:46+00:00","article_modified_time":"2026-08-21T10:28:16+00:00","og_image":[{"width":3837,"height":2540,"url":"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2016\/09\/PX2.png","type":"image\/png"}],"author":"admin","twitter_card":"summary_large_image","twitter_creator":"@pheonixsolution","twitter_site":"@pheonixsolution","twitter_misc":{"Written by":"admin","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/pheonixsolutions.com\/blog\/dynamic-dependent-drop-list-using-htmlphpmysqlajax\/#article","isPartOf":{"@id":"https:\/\/pheonixsolutions.com\/blog\/dynamic-dependent-drop-list-using-htmlphpmysqlajax\/"},"author":{"name":"admin","@id":"https:\/\/pheonixsolutions.com\/blog\/#\/schema\/person\/0ffa33d73c869faec2d50e79c24e3503"},"headline":"Dynamic dependent drop-down list using HTML, PHP, MySQL, and AJAX","datePublished":"2017-05-08T11:28:46+00:00","dateModified":"2026-08-21T10:28:16+00:00","mainEntityOfPage":{"@id":"https:\/\/pheonixsolutions.com\/blog\/dynamic-dependent-drop-list-using-htmlphpmysqlajax\/"},"wordCount":944,"commentCount":1,"publisher":{"@id":"https:\/\/pheonixsolutions.com\/blog\/#organization"},"keywords":["codeigniter","mysql","php"],"articleSection":["PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/pheonixsolutions.com\/blog\/dynamic-dependent-drop-list-using-htmlphpmysqlajax\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/pheonixsolutions.com\/blog\/dynamic-dependent-drop-list-using-htmlphpmysqlajax\/","url":"https:\/\/pheonixsolutions.com\/blog\/dynamic-dependent-drop-list-using-htmlphpmysqlajax\/","name":"Dynamic Dependent Dropdown Using PHP, MySQL & AJAX","isPartOf":{"@id":"https:\/\/pheonixsolutions.com\/blog\/#website"},"datePublished":"2017-05-08T11:28:46+00:00","dateModified":"2026-08-21T10:28:16+00:00","description":"Learn how to create a dynamic dependent dropdown using PHP, MySQL, HTML, JavaScript and AJAX to load related options without refreshing the page.","breadcrumb":{"@id":"https:\/\/pheonixsolutions.com\/blog\/dynamic-dependent-drop-list-using-htmlphpmysqlajax\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/pheonixsolutions.com\/blog\/dynamic-dependent-drop-list-using-htmlphpmysqlajax\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/pheonixsolutions.com\/blog\/dynamic-dependent-drop-list-using-htmlphpmysqlajax\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/pheonixsolutions.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Dynamic dependent drop-down list using HTML, PHP, MySQL, and AJAX"}]},{"@type":"WebSite","@id":"https:\/\/pheonixsolutions.com\/blog\/#website","url":"https:\/\/pheonixsolutions.com\/blog\/","name":"Pheonix Solutions","description":"We Empower Your Business Growth","publisher":{"@id":"https:\/\/pheonixsolutions.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/pheonixsolutions.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/pheonixsolutions.com\/blog\/#organization","name":"PheonixSolutions","url":"https:\/\/pheonixsolutions.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/pheonixsolutions.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2016\/12\/logo.png","contentUrl":"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2016\/12\/logo.png","width":454,"height":300,"caption":"PheonixSolutions"},"image":{"@id":"https:\/\/pheonixsolutions.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/PheonixSolutions-209942982759387\/","https:\/\/x.com\/pheonixsolution"]},{"@type":"Person","@id":"https:\/\/pheonixsolutions.com\/blog\/#\/schema\/person\/0ffa33d73c869faec2d50e79c24e3503","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/09bacc0294abee1322a23ab4bc6a0330dd4cb4df707dc9d0b0efeba6c109608b?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/09bacc0294abee1322a23ab4bc6a0330dd4cb4df707dc9d0b0efeba6c109608b?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/09bacc0294abee1322a23ab4bc6a0330dd4cb4df707dc9d0b0efeba6c109608b?s=96&r=g","caption":"admin"},"sameAs":["http:\/\/pheonixsolutions.com\/blog"],"url":"https:\/\/pheonixsolutions.com\/blog\/author\/admin\/"}]}},"jetpack_shortlink":"https:\/\/wp.me\/p7F4uM-o1","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1489","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=1489"}],"version-history":[{"count":4,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1489\/revisions"}],"predecessor-version":[{"id":10968,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1489\/revisions\/10968"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=1489"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=1489"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=1489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}