2012-11-17 158 views
1

您能否幫我解決這個問題?我一直在試圖在文本框中發佈內容,並試圖使用PHP'echo'來顯示它,但它一直顯示「未定義索引」,並且不會發布文本框的內容。下面的代碼:發佈索引時發生PHP錯誤

<?php 

if (isset($_POST['updateaccount'])) { 

$accountType = $_POST['typeBox']; 

echo $accountType; 
} 
?> 
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>"> 
<table> 
<tr> 
    <td><strong>Account Type<strong></td> 
    <td><input type="text" name="typeBox" value="This is a test." disabled="true"></td> 
</tr> 
<tr> 
    <td></td> 
    <td><input type="submit" name="updateaccount" value="Update Account"></td> 
</tr> 
</table> 
</form> 

每當我嘗試提交表單,它說:

公告:未定義指數:用C typeBox:\ XAMPP \ htdocs中\ cel1rcfc \上線test.php的5

回答

3

由於您設置了屬性disabled="true",因此禁用的輸入元素將不會發布到服務器端。

+0

謝謝!你真的救了我的命! –

+0

@ JianCarloV.Rubio將其標記爲最佳答案。 –

0

你標記的輸入爲「禁用」:

<input type="text" name="typeBox" value="This is a test." disabled="true"> 

所以它沒有被提交。但是,提交按鈕(updateaccount)已啓用,所以您在頂部的支票通過。

0

它是你已經設置屬性disabled="true"爲文本框的原因刪除disabled="true"以得到你想要的結果。

這樣

<input type="text" name="typeBox" value="This is a test" /> 
0

您應該刪除屬性disabled="true",使其正常工作。