2014-02-07 77 views
-2

我是新來的PHP在這裏,努力解決問題。我創建了一個表單將信息提交給後端的powershell腳本。我有一個下拉字段(電話),這是從MySQL拉動和填充。這部分工作很好。我遇到的問題是,當我發佈數據並將其傳遞給powershell腳本時,字段(電話)將作爲空白傳遞。我不確定我在哪裏可能導致問題,並在此尋找幫助。下拉選項填充MySQL選擇不張貼

這是我的。如果可能,我想保留在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: 

其他 { 回聲「對不起,您沒有完成所有必填字段請返回重試。」; } ?>

+0

你的名字= 'PHONENUM' 之間的空間。如果你刪除它會發生什麼? – chepe263

+0

@ chepe263 html標籤中的空白是無關緊要的。嘗試在'elseif'塊中執行'var_dump($ _ POST)'並查看是否發佈到頁面的變量。同樣從'

'標籤中刪除'/',因爲這不是一個自動關閉標籤,它被'
' – elitechief21

+0

關閉。檢查輸出的html並確保電話'選項'標籤的值屬性選擇'正在填充您從數據庫中獲得的ID – elitechief21

回答

0

我已經解決我自己的問題。在該行

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

我應該有

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