How to echo dependent country and state select box value after form submission in php

Here is my code.

<div class="col-sm-12">
						<div class="col-sm-5">
					<?php 
$query=$conn->query("Select * From countries Where status='1' ORDER BY country_name ASC");
$rowcount=$query->num_rows;

							?>
                                                  
							
                                                        <label for="Country">Country<sup>*</sup></label>
                                                       <!-- <input class="form-field" name="entity" id="name" type="text" placeholder="Your country">-->
													    <select name="country" id="country" class="form-field" value="<?php echo $country; ?>">
								<option value="">Select Country</option>
								<?php 
								if($rowcount>0){

                                   
									while($row=$query->fetch_assoc()){
										echo '<option value="'.$row['country_id'].'">'.$row['country_name'].'</option>';
									}
									
								}
else{
                                        echo '<option value="">Country Not Available</option>';

									}
								?>
									</select>
									
									<script type="text/javascript">
  document.getElementById('country').value = "<?php if(empty($others))
  {
  echo $_POST['country'];
  }?>";
  </script>
									
					</div>
					<div class="col-sm-2"></div>
					<div class="col-sm-5">
					   <label for="State">State<sup>*</sup></label>
                                                     
														
														 <select name="state" id="state" class="form-field" value = "<?php  echo states;?>">
									<option>Select Country First</option>
									</select>
									
									
									
										<script type="text/javascript">
  document.getElementById('state').value = "<?php  echo $_POST['state'];?>";
									
  </script>
		
		
				</div>
					</div>
					
						
					</div>

Hi @selvameena62 I’m not sure what you’re trying to solve here. Could you provide any more information?

the form is missing.

then like

// if country submitted
// select states for country
// make select box with states

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.