Skip to content
Advertisement

Dropdown value does not passing to SQL query (dropdown value came from a table)

This is my html form where i fetch a dropdown value from a table. i want to insert this dropdown value to a another table.

from_rate:<input type="text" name="from_rate" placeholder="$">
   to_rate:<input type="text" name="to_rate" placeholder="$">
   <label for="receive">From Gateway:</label>
   <?php
   $option="";
   $query="SELECT * FROM settings WHERE TRIM(usd_gateway)> '' ";
   $result=mysqli_query($con,$query);  
   ?>      
<select name='from_gateway' class='form-control col-8'>
   <?php
    while($row = mysqli_fetch_assoc($result)) {
        $currency=$row['usd_gateway'];
        echo "<option value='$currency'>$currency</option>";
    }
   ?>
  <input type="submit" value="Submit" name="submit">

my php code is following

if (isset($_POST['submit'])){
    if (empty($_POST['from_rate']) or empty ($_POST['to_rate'])){
        $err= "All field required";
    }
    else {
        $from_rate=$_POST['from_rate'];
        $to_rate=$_POST['to_rate'];
        $from_gateway=$_POST['from_gateway'];
        $to_gateway=$_POST['to_gateway'];
        $status='1';
    }
    if (empty($err)){
        $sql="INSERT INTO gateway (from_rate, to_rate, from_gateway, status) VALUES ('$from_rate','$to_rate','$from_gateway','$to_gateway','$status')";
        $result=mysqli_query($con,$sql);
        echo "Gateway direction setup completed";
    }
    
}

everything works perfectly when i removed the dropdown from the form.

Advertisement

Answer

I have just solved the problem by using foreach function. this may be helpful for someone who visiting this page.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement