下拉填充由mysql选择而不是发布

时间:2014-02-07 20:50:25

标签: php mysqli

我是PHP的新手,并且遇到了问题。我已经创建了一个表单来向后端的powershell脚本提交信息。我有一个下拉字段(电话)从mysql拉出并填充。那部分工作得很好。我遇到的问题是,当我发布数据并将其传递给powershell脚本时,该字段(电话)将作为空白传递。我不确定我在哪里引起了这个问题并在这里寻求帮助。

这就是我所拥有的。如果可能的话,我想把它保存在PHP中。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

</head>
<body>


<?php



// If there was no submit variable passed to the script (i.e. user has visited the page without clicking submit), display the form:
if(!isset($_POST["submit"]))
{
?>

<form name="testForm" id="testForm" action="BTAM2.php" method="post" /> <br />

First Name: <input type="text" name="SAMname" id="SAMname" maxlength="20" /><br />         <br/>
Telephone Number: 

<?php
$con=mysqli_connect("localhost","root","","it");
//============== check connection
if(mysqli_errno($con))
{
echo "Can't Connect to mySQL:".mysqli_connect_error();
}



//This creates the drop down box

echo "<select name='phonenum' id='phonenum'>";
echo '<option value="0">'.' '.'</option>';
$query = mysqli_query($con,"Select `btphonenumber` from `btphone` where `btuser` = ' '");
$query_display = mysqli_query($con,"SELECT * FROM btphone");

while($row=mysqli_fetch_array($query))
{
echo "<option value='". $row['id']."'>".$row['btphonenumber']

'';

}

echo '</select>';


?><br /> <br />




<input type="submit" name="submit" id="submit" value="Create User" />
</form>
<?php   
}
// Else if submit was pressed, check if all of the required variables have a value:
elseif((isset($_POST["submit"])) && (!empty($_POST["SAMname"])))
{
// Get the variables submitted by POST in order to pass them to the PowerShell script:
$firstname = $_POST["SAMname"];
$telenumber = $_POST["phonenum"];




var_dump($_REQUEST);


}
// Else the user hit submit without all required fields being filled out:

否则     {     echo“抱歉,您没有填写所有必填字段。请返回并重试。”;     }     ?&GT;          

1 个答案:

答案 0 :(得分:0)

我已经解决了自己的问题。在行

echo "<option value='". $row['id']."'>".$row['btphonenumber']

我应该有

echo "<option value='". $row['btphonenumber']."'>".$row['btphonenumber']