[英]Dropdown value does not passing to SQL query (dropdown value came from a table)
這是我的 html 表格,我從表格中獲取下拉值。 我想將此下拉值插入另一個表。
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">
我的 php 代碼如下
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";
}
}
當我從表單中刪除下拉列表時,一切正常。
我剛剛通過使用 foreach function 解決了這個問題。 這可能對訪問此頁面的人有所幫助。
我注意到你打開select
標簽,但你沒有關閉它。 嘗試關閉select
標簽
<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>";
}
?>
</select>
<input type="submit" value="Submit" name="submit">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.