我一直在我的頁面上收到未定義的索引錯誤。我嘗試過不同的事情,但似乎無法擺脫它。我有一個項目,我必須創建一個運行Server PHP Self的簡單區域轉換。PHP未定義索引PHP自我
<?php
if ($_POST['number'] == "") {
$number = '';
} else {
$number = $_POST['number'];
}
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
<label>Please Select Area Conversion Method</label>
<select name="con">
<option selected="selected"></option>
<option>Square Feet to Square Meters</option>
<option>Square Yards to Square Meters</option>
<option>Square Miles to Square Kilometers</option>
<option>Square Meters to Square Feet</option>
<option>Square Meters to Square Yards</option>
<option>Square Kilometers to Square Miles</option>
</select><br />
<label>Input Number: </label>
<input type="text" name="number" size="10" /><br />
<input type="submit" value="Calculate" name="submit" />
</form>
我試圖做if isset
和if empty
,但似乎無法擺脫undefined index error
的。
您是否也可以添加錯誤? – andrewsi 2012-07-05 19:35:54
你能發佈你如何實現IF語句 – SmokeyPHP 2012-07-05 19:36:59
'$ number = isset($ _POST ['number'])? $ _POST ['number']:'';' – nickb 2012-07-05 19:39:13