0

First of all, I am working on editing mode. I Fetch data from database then match it form selected item from last time. when I change the value of dropdown it does not change it returns me the blank value in $_POST[]

I am populating a Drop Down Box using the following code.

<select name="agency_name" class="form-control">
<option value="">--Select--</option>
<?php                                                                
$query_agency= "Select * From `agency_name`";
$count   = $db_handle->numRows($query_agency);                                   
if($count != 0){
$i = 0;                                                                    
$result_agency = $db_handle->runQuery($query_agency);
while($i != $count){                                                                        
$agencyname = $result_agency[$i]['name']; 
?>
<option value="<?php echo $result[0]['Agency_name'] ?>" 
<?php if($result[0]['Agency_name']=="$agencyname"){echo "selected";} ?>>
<?php echo $agencyname;?>
</option>
<?php     
$i++;
}
}
?>
</select>

I want to show change value and store in the database. Now how can I get the selected option value using PHP because I want the selected value to perform a query in the database.

  • 2
    Possible duplicate of [selected value get from db into dropdown select box option using php mysql error](https://stackoverflow.com/questions/18733545/selected-value-get-from-db-into-dropdown-select-box-option-using-php-mysql-error) – Ghanshyam Nakiya Jun 11 '19 at 10:10
  • you can make an `ajax` call to your back end using `onchange()` – Red Bottle Jun 11 '19 at 10:25
  • @RedBottle Could you plz give an example. – Amit Sharma Jun 11 '19 at 10:35
  • 1
    Right Click On drop down>inspect element>check if the values available in – Ashu Jun 11 '19 at 10:41
  • @AmitSharma where you found error? – Ashu Jun 11 '19 at 11:11
  • @Ashu in value is wrong code right is – Amit Sharma Jun 11 '19 at 12:44

0 Answers0