我可以从数据库中调用下拉框的值,但是我无法将所选值保存在数据库中的新行中。有人可以告诉我哪里出错了吗?
if (isset($_POST["addDestination"]) && $_POST["addDestination"]=="yes")
{
$countriesName=$_POST["countriesName"];
$Name=$_POST["Name"];
$photo=$_POST["photo"];
$description=$_POST["description"];
$Airport=$_POST["Airport"];
$Airport2=$_POST["Airport2"];
$Airline=$_POST["Airline"];
$Airline2=$_POST["Airline2"];
$Airline3=$_POST["Airline3"];
$Airline4=$_POST["Airline4"];
$dbQuery= "INSERT INTO destinations VALUES( NULL, '$countriesName', '$Name', '$photo', '$description', '$Airport', '$Airport2', '$Airline', '$Airline2', '$Airline3', '$Airline4')";
$result= mysql_query($dbQuery,$db);
从数据库中调用值的html代码和php代码是:
<form id="addDestination" name="addDestination" method="post" action="addDestination.php">
<input type="hidden" name="addDestination" value="yes">
<div id="countriesName" class="info"><span class="formLabel">Country (Please select one of the following)</span><br>
<?php
echo "<p></p>";
$dbQuery="SELECT Name FROM countries order by name asc";
$dbResult=mysql_query($dbQuery);
echo "<select name=\"Name\">";
while ($dbRow=mysql_fetch_array($dbResult)) {
$Name=$dbRow["Name"];
echo "<option value='$Name'>$Name</option>";
}
echo "</select>";
echo "<p> </p>";
?>
</div>
当我尝试保存所选值时,数据库中的字段保持空白。
答案 0 :(得分:2)
我认为这可能不是:
$countriesName=$_POST["countriesName"];
您可能需要使用:
$countriesName=$_POST["Name"];
"Name"
是您实际HTML选择的名称,而不是包含div的"countriesName"
。